English 中文(简体)
如何在日食外壳上装入动态数据?
原标题:How to load dynamic data on a eclipse shell?

我想在单击用户名称时加载用户的详细信息 。 因此我创建了一个网格布局, 左手侧有两个列是独立的, 右手侧数据将根据点击它们的名称加载 。

< 强 > JAVA CODE

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();

我在表格上添加了一个选择倾听器。当单击播放器时,我会在选择倾听器部件的选中方法上添加他们的细节 。

< 强 > JAVA CODE

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());

If i did like this on click action each time data will be appended to existing shell . How can I clear the righ hand side details ? . I posted a image below . enter image description here

我怎么能做到这一点?

最佳回答

我终于找到答案了

Issue : I append new elements into already created composite .

Solution: Clear elements from existing composite before drawing new elements .

Java 代码 :

if ((composite != null) && (!composite.isDisposed())) {
             Control[] children = composite2.getChildren();
             for(Control ch : children){
                 ch.dispose();
             }
            }
问题回答

暂无回答




相关问题
In Eclipse, why doesn t "Show In" appear for non-Java files?

If I have a *java file open, I can right click on the source, scroll down to "Show In (Alt-Shift-W)", and select Navigator. If I have an *xml, *jsp, or pretty much anything besides a Java source ...

Eclipse: Hover broken in debug perspective

Since upgrading Eclipse (Galileo build 20090920-1017), hover in debug no longer displays a variable s value. Instead, hover behaves as if I were in normal Java perspective: alt text http://...

Eclipse smart quotes - like in Textmate

Happy Friday — Does anyone know if eclipse has the notion of smart quotes like Textmate. The way it works is to select some words and quote them by simply hitting the " key? I m a newbie here so be ...

Indentation guide for the eclipse editor

Is there a setting or plugin for eclipse that can show indentation guides in the editor? Something like the Codekana plugin for visual studio (not so fancy is also OK). Important that it works with ...

Adding jar from Eclipse plugin runtime tab

I want to add .jar files for plugin from the Runtime tab of manifest file. When I use the Add... button, I can see only sub-directories of the plugin project. So if I want to add same .jar file to ...

How to copy multiple projects into single folder in eclipse

I have two projects, Project1 and Project2. Now i want to copy this projects into eclipse workspace but i want these projects to be in a single folder like below. Eclipse Workspace -> Project -> ...

Java: Finding out what is using all the memory

I have a java application that runs out of memory, but I have no idea which code is allocating the memory. Is there an application with which I can check this? I use Eclipse.

热门标签