Possible 4.2.0 bug: changing text deletes FormAttachments

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

Possible 4.2.0 bug: changing text deletes FormAttachments

Postby dannym » Fri Oct 21, 2005 3:52 pm

V4.2.0 / Eclipse 3.1.0

In the following (simple if unrealistic) test case, FormLayout is used to size a button so it fills its parent. If I then change the button text in the Property Editor, the formData.bottom and formData.right assignments are deleted, and the button is therefore unintentionally resized.

Is this a bug, or is Designer deliberately doing this?

Code: Select all
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class BugTestCase1 {

   private Button button;
   protected Shell shell;

   public static void main(String[] args) {
      try {
         BugTestCase1 window = new BugTestCase1();
         window.open();
      } catch (Exception e) {
         e.printStackTrace();
      }
   }

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

   protected void createContents() {
      final FormData formData;
      shell = new Shell();
      shell.setLayout(new FormLayout());
      shell.setSize(500, 375);
      shell.setText("Bug Test Case 1");

      button = new Button(shell, SWT.NONE);
      formData = new FormData();
      
      // The next two lines get deleted when the button text is
      // changed in the Property Editor:
      formData.bottom = new FormAttachment(100, 0);
      formData.right = new FormAttachment(100, 0);
      
      formData.top = new FormAttachment(0, 0);
      formData.left = new FormAttachment(0, 0);
      button.setLayoutData(formData);
      button.setText("button");
   }

}
dannym
 
Posts: 3
Joined: Thu Oct 20, 2005 6:12 am
Location: London, UK

Re: Possible 4.2.0 bug: changing text deletes FormAttachment

Postby Eric Clayberg » Fri Oct 21, 2005 6:46 pm

dannym wrote:In the following (simple if unrealistic) test case, FormLayout is used to size a button so it fills its parent. If I then change the button text in the Property Editor, the formData.bottom and formData.right assignments are deleted, and the button is therefore unintentionally resized. Is this a bug, or is Designer deliberately doing this?

It is deliberate. It is autosizing based on a change to the text (or image) property.

You can turn the autosizing off via the Designer > General > Property Pane > Automatically autosize widget on text or image property change preference.

Image
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 1 guest