1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| /**
* @param args program entries.
*/
public static void main(final String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
TableColumnLayout layout = new TableColumnLayout();
Composite parent = new Composite(shell, SWT.NONE);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
final int heightHint = 200;
data.heightHint = heightHint;
parent.setLayoutData(data);
parent.setLayout(layout);
Table table =
new Table(parent, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
table
.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
table.setLinesVisible(true);
table.setHeaderVisible(true);
String[] titles =
{ " ", "C", "!", "Description", "Resource", "In Folder", "Location" };
for (int i = 0; i < titles.length; i++) {
TableColumn column = new TableColumn(table, SWT.NONE);
layout.setColumnData(column, new ColumnWeightData(1));
column.setText(titles[i]);
}
final int count = 10;
for (int i = 0; i < count; i++) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText(0, "test");
item.setText(1, "y");
item.setText(2, "!");
if (i == 1) {
URL url =
Snippet.class.getClassLoader().getResource("delete.png");
if (url != null) {
ImageDescriptor descr = ImageDescriptor.createFromURL(url);
if (descr != null) {
item.setImage(new Image[] { null, null, null,
descr.createImage(), null, null, null, null });
}
}
} else {
item.setText(3, "this stuff behaves the way I expect");
}
item.setText(4, "almost everywhere");
item.setText(5, "some.folder");
item.setText(6, "line " + i + " in nowhere");
}
for (int i = 0; i < titles.length; i++) {
table.getColumn(i).pack();
}
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}] |
Partager