我试图将一些控件放到SWT上并且它们很奇怪:
即。表的大小比窗口大小长得多,因此底部滚动条末端无法访问。如果mose hovere在它上面,滚动条也会奇怪地闪烁。
为什么?
整个代码:
package tests.Try_SWT_02;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
/**
* Hello world!
*
*/
public class App01
{
public static void main( String[] args )
{
GridLayout gridLayout;
Display display = new Display ();
Shell shell = new Shell(display);
gridLayout = new GridLayout(1, false);
shell.setLayout(gridLayout);
/*
Composite presetComposite = new Composite(shell, SWT.NONE);
//presetComposite.setLayout(new FillLayout(SWT.HORIZONTAL));
gridLayout = new GridLayout(2, false);
presetComposite.setLayout(gridLayout);
Label label = new Label(presetComposite, SWT.NONE);
label.setText("Select a preset:");
Combo combo = new Combo(presetComposite, SWT.READ_ONLY);
combo.add("One");
combo.add("Two");
combo.add("Three");
*/
Table table = new Table(shell, SWT.VIRTUAL | SWT.BORDER);
TableColumn column;
column = new TableColumn(table, SWT.NONE, 0);
column.setText("Column 1");
column.setWidth(50);
column = new TableColumn(table, SWT.NONE, 1);
column.setText("Column 2");
column.setWidth(50);
column = new TableColumn(table, SWT.NONE, 2);
column.setText("Column 3");
column.setWidth(50);
int itemCount = 10000;
TableItem item;
int counter = 0;
for(int i=0; i<itemCount; ++i) {
item = new TableItem(table, SWT.NONE);
item.setText(new String[] {Integer.toString(counter++), Integer.toString(counter++), Integer.toString(counter++)});
}
shell.pack();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}