
Layout only refreshed first time
Hi,
I have a layout containing multiple SWT Labels in a row. On some action (in the example code triggered by button press), the labels should change their text and the layout should be re-arranged.
Now I have the problem, that the layout is only refreshed on the first text change (per label). I tried with and without the "nocache" option in MigLayout constructor. It didn't change anything. When i resize the shell, the layout is correctly refreshed.
For better understanding I'm attaching 4 screenshots put together. The last one "After pressing left button 2nd time" should in my opinion look exactly like the second one "After pressing left button".
Here is my code:
Code:
package test;
import net.miginfocom.swt.MigLayout;
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.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class Test {
public static void main(final String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout(SWT.VERTICAL));
final Composite cmpLabels = new Composite(shell, SWT.BORDER);
cmpLabels.setLayout(new MigLayout("nocache, wrap 5"));
final Label l0 = new Label(cmpLabels, SWT.NONE);
l0.setText("L 0");
final Label l1 = new Label(cmpLabels, SWT.NONE);
final Label l2 = new Label(cmpLabels, SWT.NONE);
l2.setText("L 2");
final Label l3 = new Label(cmpLabels, SWT.NONE);
final Label l4 = new Label(cmpLabels, SWT.NONE);
l4.setText("L 4");
final Composite cmpButtons = new Composite(shell, SWT.NONE);
cmpButtons.setLayout(new FillLayout());
final Button btn1 = new Button(cmpButtons, SWT.PUSH);
btn1.setText("Set 1");
btn1.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
changeText(l1);
resetText(l3);
cmpLabels.layout();
}
});
final Button btn3 = new Button(cmpButtons, SWT.PUSH);
btn3.setText("Set 3");
btn3.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
resetText(l1);
changeText(l3);
cmpLabels.layout();
}
});
shell.setSize(300, 100);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
protected static void changeText(final Label label) {
label.setText("Some text");
}
protected static void resetText(final Label label) {
label.setText("");
}
}
I'm using MigLayout 3.7.4.
I would appreciate any hints or help.