Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SWT:表大小调整问题_Java_Uitableview_User Interface_Swt - Fatal编程技术网

Java SWT:表大小调整问题

Java SWT:表大小调整问题,java,uitableview,user-interface,swt,Java,Uitableview,User Interface,Swt,我正在做一个家庭作业项目,其中向用户显示一个产品目录,然后用户从目录中选择一个产品进行购买 我决定使用SWT构建一个基本的UI。更不用说我刚刚开始学习SWT 这就是我到目前为止所做的。UI的第一个组件是一个表,它显示产品目录。此文件的代码段: private void displayProductCatalog(List<Product> productList) { Group group = new Group(shell, SWT.NULL);

我正在做一个家庭作业项目,其中向用户显示一个产品目录,然后用户从目录中选择一个产品进行购买

我决定使用SWT构建一个基本的UI。更不用说我刚刚开始学习SWT

这就是我到目前为止所做的。UI的第一个组件是一个
,它显示产品目录。此文件的代码段:

private void displayProductCatalog(List<Product> productList) {
        Group group = new Group(shell, SWT.NULL);
        group.setLayout(new GridLayout());
        Label label = new Label(group, SWT.NULL);
        label.setAlignment(SWT.CENTER);
        label.setText("Plese select a product by clicking on the desired row.");

        Table table = new Table(group, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
        table.setLinesVisible(true);
        table.setHeaderVisible(true);
        GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
        table.setLayoutData(data);
        String[] titles = { "Product ID", "Product Description", "Cost" };
        for (int i = 0; i < titles.length; i++) {
            TableColumn column = new TableColumn(table, SWT.BOLD | SWT.CENTER);
            column.setText(titles[i]);
            column.setWidth(300);
        }

        String currency = " " + CurrencyHelper.fetchCurrency();

        for (Product product : productList) {
            ProductDescription productDescription = product.getProductDescription();
            TableItem item = new TableItem(table, SWT.NONE);
            item.setText(0, productDescription.getProductId());
            item.setText(1, productDescription.getDescription());
            item.setText(2, productDescription.getPrice().toString() + currency);
        }

        table.addSelectionListener(new TableRowSelectionListener(vendingMachine));
    }
在UI启动时:

当用户选择产品时:

如您所见,填充表时,第二个表不会调整大小。虽然表格有一个垂直滚动窗格,但从用户的角度来看,这是一个不便


你能帮我一下吗。我不确定这里到底出了什么问题。

如果希望包含此数据的
Shell
调整大小,需要在向表中添加条目后调用
Shell
pack()
方法。这将导致外壳重新计算外壳大小并重新进行组件布局。

如果要调整包含此数据的
shell
大小,需要在向表中添加条目后调用
shell
pack()
方法。这将导致外壳重新计算外壳大小并重做组件布局

private void displaySaleLineItem(List<Product> productList) {
        Group group = new Group(shell, SWT.NULL);
        group.setLayout(new GridLayout());
        Label label = new Label(group, SWT.NULL);
        label.setAlignment(SWT.CENTER);
        label.setText("Product Details.");

        saleLineItemTable = new Table(group, SWT.BORDER);
        saleLineItemTable.setLinesVisible(true);
        saleLineItemTable.setHeaderVisible(true);
        // GridData data = new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1);
        // saleLineItemTable.setLayoutData(data);
        for (int i = 0; i < 2; i++) {
            TableColumn column = new TableColumn(saleLineItemTable, SWT.BOLD | SWT.CENTER);
            column.setWidth(450);
        }
    }
@Override
    public void onPropertyEventBeforeSale(Sale sale) {
        TableItem item = new TableItem(saleLineItemTable, SWT.NONE);
        item.setText(0, sale.getProduct().getProductDescription().getDescription());
        item.setText(1, sale.getProduct().getProductDescription().getPrice().toString());

        for (TaxTypeModel taxTypeModel : sale.getTaxModel().getTaxTypeModelList()) {
            item = new TableItem(saleLineItemTable, SWT.NONE);
            item.setText(0, taxTypeModel.getTaxName());
            item.setText(1, taxTypeModel.getTaxValue().toString() + "%");
        }

        item = new TableItem(saleLineItemTable, SWT.NONE);
        item.setText(0, "TOTAL");
        item.setText(1, sale.getTaxModel().getProductPriceIncludingTax().toString());
    }