View unanswered posts | View active topics It is currently Sat Jul 26, 2014 10:05 am



Reply to topic  [ 6 posts ] 
 Layout only refreshed first time 
Author Message

Joined: Fri Apr 01, 2011 5:02 pm
Posts: 5
Post 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.


Attachments:
screenshots.png
screenshots.png [ 41.64 KiB | Viewed 1881 times ]
Fri Apr 01, 2011 5:26 pm
Profile

Joined: Fri Apr 01, 2011 5:02 pm
Posts: 5
Post Re: Layout only refreshed first time
Hi,

does nobody have an idea or hint?

Greetings

TAL


Tue Apr 26, 2011 4:35 pm
Profile

Joined: Mon Aug 23, 2010 6:24 am
Posts: 54
Post Re: Layout only refreshed first time
Hi Tal,

I don't know SWT but if you were using Swing you'd have to revalidate() each component whose layout should change.

Gili


Wed May 11, 2011 4:28 pm
Profile

Joined: Fri Apr 01, 2011 5:02 pm
Posts: 5
Post Re: Layout only refreshed first time
Hi Gili,

thanks for your hint.

In SWT there is redraw() and update() for Components. The layout() on the parent should refresh the layouting.

But no combination of the three (on the labels, the composite or entire shell) did solve my problem.

Greetings
Tobi


Thu May 12, 2011 2:32 pm
Profile
Site Admin

Joined: Mon Dec 06, 2004 4:24 pm
Posts: 2485
Location: Sweden
Post Re: Layout only refreshed first time
Hello,

This was a hasing bug. It is fixed in v4.0.

Thanks,
Mikael


Sat Aug 13, 2011 1:24 am
Profile WWW

Joined: Fri Apr 01, 2011 5:02 pm
Posts: 5
Post Re: Layout only refreshed first time
Thank you very much. I will switch to 4.0 then :-)


Wed Aug 17, 2011 12:46 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.