我想在单击用户名时加载用户的详细信息。所以我创建了一个网格布局,其中两列左侧是独立的,右侧数据将根据单击它们的名称来加载。
JAVA代码
Display display = PlatformUI.createDisplay();
Shell shell = new Shell(display);
shell.setSize(400, 400);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
shell.setLayout(gridLayout);
shell.setBackground(new Color(display, 255, 255, 255));
final Table table = new Table(shell, SWT.VIRTUAL);
table.setLayout(new GridLayout());
table.setSize(400, 400);
final TableColumn column = new TableColumn(table, SWT.LEFT);
column.setWidth(150);
column.setText("Runnable Services");
table.setItemCount(5);
final String[] services = new String[] { "Franklin", "Christian",
"Richard Levi",
"Dale Steyn", "Chris Gayle" };
table.addListener(SWT.SetData, new Listener() {
public void handleEvent(Event event) {
TableItem item = (TableItem) event.item;
int index = table.indexOf(item);
item.setText(services[index]);
System.out.println(item.getText());
}
});
table.addSelectionListener(new OnClickListener());
alignCenter(shell, display);
shell.open();
我在 table 上添加了一个选择侦听器。单击播放器时,我将他们的详细信息添加到 SelectionListener 的小部件 Selected 方法中。
JAVA代码
Composite parent = new Composite(table.getParent(), SWT.NONE);
parent.setLayout(new GridLayout(2, false));
Label label = new Label(parent, SWT.NULL);
label.setText("Name :");
System.out.println(table.getSelection()[0].getText());
Text text = new Text(parent, SWT.BORDER);
text.setText(table.getSelection()[0].getText());
text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL
| GridData.GRAB_HORIZONTAL));
ViewActionDelegate.resize(200, true, 20, table.getShell());
如果我在每次点击操作时都喜欢这个,那么数据将被附加到现有的 shell 中。我怎样才能清除右手边的细节?. 我在下面贴了一张图片。
我怎样才能做到这一点 ?.