GroupLayout and Composite+layout(true)

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

GroupLayout and Composite+layout(true)

Postby dspasojevic » Tue Feb 06, 2007 8:09 pm

Hi,

I am wondering whether GroupLayout properly supports being asked to lay itself out in response to a invocation of Composite+layout(true).

If I use a TableWrapLayout to layout a Label, a Text and a Button, and change the text of the Label to be something longer in the selection listener of the button then call label.getParent().layout(true) the controls are relaid out so that the entirety of the Label is visible. That sounds a bit confusing, so I have attached a test case at the bottom of the post.

However if I use a GroupLayout to do the same thing, the controls are not relaid out so that the label is completely visible. Is this the expected behavour?

This is the horizontal layout part of the code (attached in full at bottom of message).

Code: Select all
      groupLayout.setHorizontalGroup(
         groupLayout.createParallelGroup(GroupLayout.LEADING)
            .add(groupLayout.createSequentialGroup()
               .addContainerGap()
               .add(label)
               .addPreferredGap(LayoutStyle.RELATED)
               .add(text, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE)
               .addPreferredGap(LayoutStyle.RELATED)
               .add(button)
               .addContainerGap(291, Short.MAX_VALUE))
      );


I thought that since the label does not have a maximum size constraint, it would be allocated its preferred size when it is laid out.

Thanks in advance for any help,

-Dan

|----- GroupLayout test ---------------|

Code: Select all
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.grouplayout.GroupLayout;
import org.eclipse.swt.layout.grouplayout.LayoutStyle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;


public class ResizeGLTest {

   private Text text;
   protected Shell shell;

   /**
    * Launch the application
    * @param args
    */
   public static void main(String[] args) {
      try {
         ResizeGLTest window = new ResizeGLTest();
         window.open();
      } catch (Exception e) {
         e.printStackTrace();
      }
   }

   /**
    * Open the window
    */
   public void open() {
      final Display display = Display.getDefault();
      createContents();
      shell.open();
      shell.layout();
      while (!shell.isDisposed()) {
         if (!display.readAndDispatch())
            display.sleep();
      }
   }

   /**
    * Create contents of the window
    */
   protected void createContents() {
      shell = new Shell();
      shell.setText("SWT Application");

      final Label label;
      label = new Label(shell, SWT.NONE);
      label.setText("Label");

      text = new Text(shell, SWT.BORDER);

      Button button;
      button = new Button(shell, SWT.NONE);
      button.setText("button");
      button.addSelectionListener(new SelectionListener() {

         public void widgetDefaultSelected(SelectionEvent e) {
            // TODO Auto-generated method stub
            
         }

         public void widgetSelected(SelectionEvent e) {
            label.setText("something a lot longer");
            label.getParent().layout(true);
         }
         
      });
      final GroupLayout groupLayout = new GroupLayout(shell);
      groupLayout.setHorizontalGroup(
         groupLayout.createParallelGroup(GroupLayout.LEADING)
            .add(groupLayout.createSequentialGroup()
               .addContainerGap()
               .add(label)
               .addPreferredGap(LayoutStyle.RELATED)
               .add(text, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE)
               .addPreferredGap(LayoutStyle.RELATED)
               .add(button)
               .addContainerGap(291, Short.MAX_VALUE))
      );
      groupLayout.setVerticalGroup(
         groupLayout.createParallelGroup(GroupLayout.LEADING)
            .add(groupLayout.createSequentialGroup()
               .addContainerGap()
               .add(groupLayout.createParallelGroup(GroupLayout.BASELINE)
                  .add(label)
                  .add(text, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
                  .add(button))
               .addContainerGap(328, Short.MAX_VALUE))
      );
      shell.setLayout(groupLayout);
      shell.pack();
      //
   }

}


|----- TableWrapLayout test ---------------|

Code: Select all
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.TableWrapData;
import org.eclipse.ui.forms.widgets.TableWrapLayout;


public class ResizeFLTest {

   private Text text;
   protected Shell shell;

   /**
    * Launch the application
    * @param args
    */
   public static void main(String[] args) {
      try {
         ResizeFLTest window = new ResizeFLTest();
         window.open();
      } catch (Exception e) {
         e.printStackTrace();
      }
   }

   /**
    * Open the window
    */
   public void open() {
      final Display display = Display.getDefault();
      createContents();
      shell.open();
      shell.layout();
      while (!shell.isDisposed()) {
         if (!display.readAndDispatch())
            display.sleep();
      }
   }

   /**
    * Create contents of the window
    */
   protected void createContents() {
      shell = new Shell();
      final TableWrapLayout tableWrapLayout = new TableWrapLayout();
      tableWrapLayout.numColumns = 3;
      shell.setLayout(tableWrapLayout);
      shell.setSize(500, 375);
      shell.setText("SWT Application");

      final Label label = new Label(shell, SWT.NONE);
      label.setText("Label");

      text = new Text(shell, SWT.BORDER);
      final TableWrapData tableWrapData = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP);
      tableWrapData.maxWidth = 36;
      text.setLayoutData(tableWrapData);

      final Button button = new Button(shell, SWT.NONE);
      button.setText("button");
      button.addSelectionListener(new SelectionListener() {

         public void widgetDefaultSelected(SelectionEvent e) {
            // TODO Auto-generated method stub
            
         }

         public void widgetSelected(SelectionEvent e) {
            label.setText("something a lot longer");
            label.getParent().layout(true);
         }
         
      });
      //
   }

}
dspasojevic
 
Posts: 1
Joined: Tue Feb 06, 2007 7:24 pm

Re: GroupLayout and Composite+layout(true)

Postby Eric Clayberg » Wed Feb 07, 2007 7:39 am

Give this another try in the latest SWT Designer build.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 2 guests