Community
Participate
Working Groups
Build Identifier: 20090920-1017 When a section is displayed on the screen, calling setText(..) has no visible effect. As a workaround you can call layout() after you change the text. (I am trying to do databinding on the section text so it shows the number of elements in a table inside it. Calling SWTObservables.observeText(section) is illegal, but PojoObservables.observeValue(section, "text") should work for my needs, but it doesn't work because of this problem). import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.Section; /** * This snippet shows that changing the text in the Section does not update the * text in the UI, but it does after calling {@link Section#layout()} (or * implicitly by clicking the expander). * * @author Henno Vermeulen */ public class SnippetCompositeWithSection extends Composite { private final FormToolkit toolkit = new FormToolkit(Display.getCurrent()); private Section section; /** * Create the composite. * * @param parent * @param style */ public SnippetCompositeWithSection(Composite parent, int style) { super(parent, style); toolkit.adapt(this); toolkit.paintBordersFor(this); setLayout(new GridLayout()); section = toolkit.createSection(this, Section.EXPANDED | Section.TWISTIE | Section.TITLE_BAR); section .setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1)); toolkit.paintBordersFor(section); section.setText("Testtext"); Button btnChangeText = toolkit.createButton(section, "Change text", SWT.NONE); btnChangeText.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { System.out.println("Changing Section text, current text = " + section.getText()); section.setText(section.getText() + "!"); // Uncomment this for a workaround: // section.layout(); System.out.println("Changed Section text = " + section.getText()); } }); section.setClient(btnChangeText); } public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); new SnippetCompositeWithSection(shell, SWT.NONE); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } } } Reproducible: Always Steps to Reproduce: 1. Show a UI with a section with a title text. 2. Call setText on it with a new title text. 3. The new text does not show although section.getText() returns the new text. 4. (Or run my SnippetCompositeWithSection, press the button, check what happens, then press the expander and see the text change)
Note that the problem is probably with it's super class ExpandableComposite.
Forms is owned by UA.
The problem occurs when the new text is larger than the old text - the layout is not recomputed to allocate space for the longer label. It seems that ExpandableComposite.setText() needs to recompute the layout when it runs into the situation in the example although it should not be calling layout() for every call to setText().
*** This bug has been marked as a duplicate of bug 168745 ***