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");
}
}