0

这是我的代码,它实际上为域完成了所有 GUI 工作(右侧包含在所附图片中)。在这个函数中,我正在做的是在“newTabFolder”上创建一个复合“测试”。然后我正在创建 ScrolledComposite “sc”,然后在其上创建一个复合“compositeInTab”,在将所有小部件放在“compositeInTab”上之后,我正在创建一个 TabItem 用于在其上放置复合“测试”。

public DomainUI(Composite composite, TabFolder newTabFolder, boolean comingFromSelf)
{
    Composite test = new Composite(newTabFolder,SWT.NONE);
    test.setLayout(new FillLayout());
    ScrolledComposite sc = new ScrolledComposite(test, SWT.V_SCROLL|SWT.H_SCROLL);
    final Composite compositeInTab = new Composite(sc, SWT.NONE);
    sc.setExpandHorizontal(true); 
    sc.setExpandVertical(true);
    sc.setMinHeight(compositeInTab.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
    sc.setMinWidth(compositeInTab.computeSize(SWT.DEFAULT, SWT.DEFAULT).x);
    sc.setContent(compositeInTab);
    compositeInTab.setLayout(null);
    sc.setAlwaysShowScrollBars(true);

    /*HERE I AM CREATING LABELS AND TEXT FIELDS AND SETTING THEIR BOUNDS*/
    systemCodeLabel = new Label(compositeInTab, 0);
    systemCodeText = new Text(compositeInTab, SWT.BORDER);
    systemCodeLabel.setText("System Code");
    systemCodeLabel.setBounds(350, 60, 100, 15);
    systemCodeText.setBounds(480, 60, 150, 17);
    // CREATION OF LABELS AND TEXTFIELDS ENDED

    // CREATION OF TABLE STARTS
    myTable = new CreateTable(compositeInTab, 1);
    myTable.setBounds(50, 230, 0, 0);
    myTable.table.setSize(myTable.table.computeSize(570, 250));

    //here i filled data in table

    for(int i=0; i<myTable.table.getColumnCount(); i++)
    {
        myTable.table.getColumn(i).pack();
     myTable.table.getColumn(i).setWidth(myTable.table.getColumn(i).getWidth()+10);
    }

    TabItem tabItem1 = new TabItem(newTabFolder, SWT.NONE);
    tabItem1.setText("Domain");
    tabItem1.setControl(test);
    newTabFolder.setBounds(0, 0, 480, 300);
}
4

1 回答 1

0

这似乎是布局的问题。我摆弄了一下,设法让它工作:

public static void main(String[] args)
{
    Display display = Display.getDefault();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    ScrolledComposite scrollComp = new ScrolledComposite(shell, SWT.V_SCROLL | SWT.H_SCROLL);
    Composite innerComp = new Composite(scrollComp, SWT.NONE);
    innerComp.setLayout(new GridLayout(4, true));

    for(int i = 0; i < 32; i++)
        new Button(innerComp, SWT.PUSH).setText("Button");

    scrollComp.setMinHeight(innerComp.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
    scrollComp.setMinWidth(innerComp.computeSize(SWT.DEFAULT, SWT.DEFAULT).x);
    scrollComp.setContent(innerComp);
    scrollComp.setExpandHorizontal(true);
    scrollComp.setExpandVertical(true);
    scrollComp.setAlwaysShowScrollBars(true);

    shell.pack();
    shell.open();

    shell.setSize(200, 200);

    while(!shell.isDisposed())
    {
        if(!display.readAndDispatch())
            display.sleep();
    }
}

它将显示滚动条。但是,如果我将 shell 的布局更改为 a GridLayout,它将不起作用。也许您的布局“组合”似乎是问题所在......

于 2012-08-24T15:24:35.190 回答