[英]how to add more than one items in one CTabItem?
CTabItem tabItem1 = new CTabItem(newTabFolder, SWT.CLOSE);
tabItem1.setText("Tab 1");
Label lab2 = new Label(newTabFolder, 0);
lab2.setText("Hello World");
tabItem1.setControl(table);
tabItem1.setControl(lab2);
我正在嘗試使用具有表以及一些標簽和文本字段的CTabItem
但是出現的問題是通過使用setControl(Control control)
函數添加了任何項目/小部件。 而且我不能通過兩個以上的控件。 上面的代碼首先添加了一個表,然后用標簽將其覆蓋,因此一次僅顯示一個項目。
我一次想要兩件事。
我也嘗試過查看是否可以將內容添加到Control的對象中,然后將該控件傳遞給setControl()
函數,但是找不到任何可以添加控件的函數,請告訴我如何執行此操作。
final Composite compositeInTab = new Composite(newTabFolder, SWT.NONE);
compositeInTab.setLayout(new FillLayout());
table = new Table(compositeInTab, SWT.V_SCROLL);
btn1.addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent e)
{
/*JUST CREATING A TABLE AND MANAGING IT*/
String[] titles = {"System Code","Domain Name","Organizational Unit","Organization Name"};
for(int i=0; i<titles.length; i++)
{
TableColumn column = new TableColumn(table, SWT.CENTER, i);
column.setText(titles[i]);
column.setWidth(150);
column.setMoveable(true);
column.setResizable(true);
}
for(int i=0; i<50; i++)
{
TableItem item = new TableItem(table, 0);
item.setText(0, ""+i);
item.setText(1, ""+i);
item.setText(2, ""+i);
item.setText(3, ""+i);
}
for (int i = 0; i < titles.length; i++)
{
table.getColumn(i).pack();
}
table.setHeaderVisible(true);
table.setSize(table.computeSize(SWT.DEFAULT, 200));
table.setLinesVisible(true);
/*CREATING OF TABLE COMPLETE*/
compositeForTabFolder.setLayout(new GridLayout());
compositeForTabFolder.setBounds(280, 0, 500, 450);
newTabFolder.setUnselectedCloseVisible(false);
CTabItem tabItem1 = new CTabItem(newTabFolder, SWT.CLOSE);
tabItem1.setText("Tab 1");
Label lab2 = new Label(compositeInTab, 0);
lab2.setText("Hello World");
Label lab3 = new Label(compositeInTab, 0);
lab3.setText("Bye Bye World");
tabItem1.setControl(compositeInTab);
newTabFolder.setBounds(0, 0, 500, 300);
}
});
您可以使用Composite
,然后將所需的所有內容添加到此Composite
,然后使用setControl(composite)
。
這樣,您只需要通過setControl()
添加一個小部件,但是此小部件可以有多setControl()
。
有一個很好的例子在這里 。
這是此站點的示例代碼(稍作修改):
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
final TabFolder tabFolder = new TabFolder(shell, SWT.BORDER);
for (int i = 0; i < 6; i++) {
TabItem item = new TabItem(tabFolder, SWT.NONE);
item.setText("TabItem " + i);
item.setToolTipText("This is my tab" + i);
Composite composite = new Composite(tabFolder, SWT.NONE);
composite.setLayout(new FillLayout());
new Button(composite, SWT.PUSH).setText("Button");
new Text(composite, SWT.BORDER).setText("TextField");
new Label(composite, SWT.NONE).setText("Label");
Table table = new Table(composite, SWT.NONE);
table.setHeaderVisible(true);
new TableItem(table, SWT.NONE).setText("TableItem");
item.setControl(composite);
}
tabFolder.pack();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.