📄 tabledemo.java
字号:
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.graphics.*;
public class TableDemo {
public static Display myDisplay;
public static boolean internalCall = false;
public static void main(String[] args) {
internalCall = true;
myDisplay = new Display();
TableDemo td = new TableDemo();
td.runDemo(myDisplay);
}
public void runDemo(Display display) {
myDisplay = display;
Shell shell = new Shell(display);
shell.setSize(300,300);
shell.setText("Table Demo");
Table table1 = new Table(shell, SWT.BORDER);
table1.setBounds(10,10,270,60);
table1.setLinesVisible(true);
TableColumn name = new TableColumn(table1,SWT.LEFT);
name.setText("Name");
name.setWidth(50);
TableColumn age = new TableColumn(table1,SWT.RIGHT);
age.setText("Age");
age.setWidth(30);
TableColumn address = new TableColumn(table1,SWT.LEFT);
address.setText("Address");
address.setWidth(200);
TableItem item1 = new TableItem(table1,SWT.NONE);
item1.setText(new String[] {"Sarah","15","390 Sussex Ave"});
TableItem item2 = new TableItem(table1,SWT.NONE);
item2.setText(new String[] {"Joseph","56","7 Yourstreet St"});
Table table2 = new Table(shell, SWT.CHECK|SWT.HIDE_SELECTION);
table2.setBounds(10,80,270,80);
table2.setHeaderVisible(true);
TableColumn fruit = new TableColumn(table2,SWT.LEFT);
fruit.setText("Fruit");
fruit.setWidth(100);
TableColumn colour = new TableColumn(table2,SWT.LEFT);
colour.setText("Colour");
colour.setWidth(170);
TableItem fruit1 = new TableItem(table2,SWT.NONE);
fruit1.setText(0,"Apple");
fruit1.setText(1,"Red");
fruit1.setChecked(true);
TableItem fruit2 = new TableItem(table2,SWT.NONE);
fruit2.setText(new String[] {"Kiwi","Green"});
fruit2.setBackground(new Color(display,255,0,0));
TableItem fruit3 = new TableItem(table2,SWT.NONE);
fruit3.setText(new String[] {"Banana","Yellow"});
Table table3 = new Table(shell, SWT.FULL_SELECTION);
table3.setLinesVisible(true);
table3.setBounds(10,180,270,80);
TableColumn first = new TableColumn(table3,SWT.LEFT);
first.setResizable(true);
first.setText("First");
first.setWidth(80);
TableColumn second = new TableColumn(table3,SWT.CENTER);
second.setText("Second");
second.setWidth(80);
TableColumn third = new TableColumn(table3,SWT.RIGHT);
third.setText("Third");
third.setWidth(80);
String[] numbers = new String[] {"One","Two","Three"};
TableItem firstItem = new TableItem(table3,SWT.NONE);
firstItem.setText(numbers);
TableItem secondItem = new TableItem(table3,SWT.NONE);
secondItem.setText(numbers);
TableItem thirdItem = new TableItem(table3,SWT.NONE);
thirdItem.setText(numbers);
TableItem fourthItem = new TableItem(table3,SWT.NONE);
fourthItem.setText(numbers);
table3.select(1);
shell.open();
while(!shell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
}
if (internalCall) display.dispose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -