2009年5月12日

Eclipse SWT Virtual Table

Eclipse Virtual Tables and Trees

//-- Main.java --
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;

public class Main extends Composite {

private Table table = null;

public static void main(String[] args) {

Display display = Display.getDefault();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setSize(new Point(300, 200));
new Main(shell, SWT.NONE);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

public Main(Composite parent, int style) {
super(parent, style);
initialize();

table.setItemCount(Short.MAX_VALUE);
table.addListener(SWT.SetData, new Listener() {

public void handleEvent(Event event) {
TableItem item = (TableItem)event.item;
String text = String.format("%d", event.index);
item.setText(text);
}

});
}

private void initialize() {
table = new Table(this, SWT.NONE | SWT.VIRTUAL);
table.setHeaderVisible(true);
table.setLinesVisible(true);
setSize(new Point(300, 200));
setLayout(new FillLayout());
}

}

沒有留言:

網誌存檔