为什么在使用scrolledcomposite swt时,tabitem上的小部件是不可见的?

ercv8c1e  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(315)

下面是我的代码,它实际上完成了域的所有gui工作(右侧包含在所附图片中)。在这个函数中,我所做的是在“newtabfolder”上创建一个复合“test”。然后我在它上面创建scrolledcomposite“sc”,然后在它上面创建一个复合“compositeintab”,然后将所有小部件放在上面“compositeintab”我正在创建一个tabitem,用于将复合“test”放置在其上。

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);
}
xzv2uavs

xzv2uavs1#

这似乎是一个布局的问题。我做了一点手脚,设法让它工作起来:

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的布局更改为 GridLayout ,它将不起作用。也许你的“组合”布局似乎是问题所在。。。

相关问题