这是我的代码,它实际上完成了域的所有GUI工作(右侧包含在附图中)。在这个函数中我正在做的是我在“newTabFolder”上创建一个复合“测试”。然后我我正在创建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);
}
答案 0 :(得分: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的布局更改为GridLayout
,它将无法正常工作。也许你的布局“组合”似乎是问题......