2

I have a jFace wizard, I am using this to create a new project type eclipse plugin. As you can see from image below, I have one treeviewer on left side, and a SWT group on right side. What I want is when ever user selects one of the item from treeviewer, I should be able to create dynamic controls on right side SWT Group. Say user selects Test One, one right side I should be able to create few controls like label, text and few radio buttons on right side, similarly if user selects Test Two I should be able to create dynamic controls on right side. enter image description here

Currently I tried below code:

tree.addSelectionListener(new SelectionAdapter() {
     @Override
 public void widgetSelected(SelectionEvent e) {
     for (int i = 0; i < selection.length; i++) {

     String tempStr = selection[i].toString();
     tempStr = tempStr.replaceAll("TreeItem \\{", "");
     String finalStr = tempStr.replaceAll("\\}", "");

         if (finalStr.equals("Test One")) {
             Button btn = new Button(g2, SWT.NONE); //g2 is right side group

             btn.setText("Blaaaa");

             btn.setVisible(true);
             container.redraw();
         }

}

But when I run, I see no changes on right group. Can anyone guide me what I am doing wrong? Any pointers would be very appreciated, since I am new to Eclipse development and SWT.

Pradeep Simha
  • 17,683
  • 18
  • 56
  • 107

1 Answers1

4

You probably didn't set a layout on the g2 group. This is the common cause for controls not showing up. You can also try using g2.layout() to ensure that the new controls are correctly laid out after you create them.

Additionally you could look at using a StackLayout so that once you create a set of controls you can just hide them all at once instead of destroying when the selection changes. This is often useful so that if the user comes back to a previous selection, they will find the data they entered in the same state when they switched the selection. Here is an example.

Waqas Ilyas
  • 3,116
  • 1
  • 17
  • 27