2

We have a tool, that has a GUI which contains multiple Sections. In these sections, we have Expandable Composites which are not expanded by default. When we try to expand these composites, the + becomes a -, but it stays closed:
Expandable Composite stays closed

To fix this, I tried to add an ExpansionListener:

ExpandableComposite extendedConfiguration = getToolkit().createExpandableComposite(parent, TREE_NODE);
extendedConfiguration.setLayoutData(new GridData(FILL, CENTER, true, false, 2, 1));
extendedConfiguration.setText("Erweiterte Einstellungen");
extendedConfiguration.setExpanded(false);
extendedConfiguration.addExpansionListener(new ExpansionAdapter() {
    @Override
    public void expansionStateChanged(ExpansionEvent e) {
        parent.getParent().getParent().layout();
    }
});

Using this dirty bit of code, it works, parent is the Composite of the parent. The parent of the parent is the Section itself, the parent of the Section is our view. It not only looks stupid, but also is problematic when we want to change our view, as the parent of the parent ... may won't be the right parent.

What is the correct way to layout our view again? How can I force the UI to draw the contents of our ExpandableComposite?

looper
  • 1,929
  • 23
  • 42
  • Have you tried to use `pack();` instead of `layout();` ? If you use org.eclipse.forms.ui.Form you can also try `form.reflow(true);` instead of `layout();` – jens-na May 23 '13 at 08:24
  • @jens-na: I'm not using a form, it's just a composite. Also, pack() doesn't help here. – looper May 23 '13 at 08:51
  • The content which should be expanded should be the client of the expandable composite. E.g.: `extendedConfiguration.setClient(contentComposite);`. Do you have something like this in your code? – jens-na May 23 '13 at 11:00
  • @jens-na Yes, the composite is set as client. The parent of the composite is also the `extendedConfiguration`, as documented for `setClient`. – looper May 23 '13 at 11:05

3 Answers3

0

I think just firing resize event should do the trick for you

 parent.getParent().layout(true);
 parent.getParent().notifyListeners(SWT.Resize, null);
sambi reddy
  • 3,065
  • 1
  • 13
  • 10
0

First: try to invalidate your composite component.

Daniel De León
  • 13,196
  • 5
  • 87
  • 72
0

You can do a layout of the top level window:

extendedConfiguration.getShell().layout();

Source: SWT counterpart of revalidate method of SWING's JComponent

flup
  • 26,937
  • 7
  • 52
  • 74