[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] Strange behavior of FormLayout

That's the solution! Thanks a lot! (-:
 

From: Vinh Hoang
Sent: Monday, June 07, 2010 3:07 PM
Subject: Re: [platform-swt-dev] Strange behavior of FormLayout

Its been awhile since I've did SWT now, but maybe you try to do a panel.layout and/or panel.contentPanel.layout.  



2010/6/7 Michał Kowalczyk (ekk) <mkk@xxxxxx>
I try to create MovablePanel class which inherits from Composite. MovablePanel is composed of Header Composite (which contains Label - panel name) and Content Composite.
It would be nice if I could add Controls (for example Text) to Content Composite outside class definition. Unfortunately it doesn't work. Take a look at case 1 and case 2 of my code.
 

CASE 1
 
// Class definition
 
public class MovablePanel extends Composite{
 protected Label labelHeader;
 protected Composite compositeHeader;
 public Composite compositeContent;
 
 
 public MovablePanel(Composite parent, int style){
  super(parent, style);
  setLayout(new FormLayout());
  
  FormData formData;
  
  compositeHeader = new Composite(this, SWT.BORDER);
  
  labelHeader = new Label(compositeHeader, SWT.NONE);
  labelHeader.setText("Nazwa panelu");
  labelHeader.pack();
  formData = new FormData();
  formData.left = new FormAttachment(0, 5);
  formData.top = new FormAttachment(0, 5);
  labelHeader.setLayoutData(formData);
  
  formData = new FormData();
  formData.left = new FormAttachment(0, 0);
  formData.right = new FormAttachment(100, 0);
  formData.top = new FormAttachment(0, 0);
  compositeHeader.setLayoutData(formData);
  
  compositeContent = new Composite(this, SWT.BORDER);
  formData = new FormData();
  formData.left = new FormAttachment(0, 0);
  formData.right = new FormAttachment(100, 0);
  formData.top = new FormAttachment(compositeHeader, 0);
  formData.bottom = new FormAttachment(100, 0);
  compositeContent.setLayoutData(formData);
  compositeContent.setLayout(new FormLayout());
  
  Text text = new Text(compositeContent, SWT.SINGLE);
  text.setText("123");
  formData = new FormData();
  formData.left = new FormAttachment(0, 5);
  formData.right = new FormAttachment(100, -5);
  formData.top = new FormAttachment(0, 5);
  formData.bottom = new FormAttachment(100, -5);
  text.setLayoutData(formData);
 }
}
 
// Creating instance
 
  MovablePanel panel = new MovablePanel(shell, SWT.BORDER);
  panel.setBounds(0, 0, 300, 150);
 
//----------------------
 
 
 
CASE 2
 
// Class definition
 
public class MovablePanel extends Composite{
 protected Label labelHeader;
 protected Composite compositeHeader;
 public Composite compositeContent;
 
 
 public MovablePanel(Composite parent, int style){
  super(parent, style);
  setLayout(new FormLayout());
  
  FormData formData;
  
  compositeHeader = new Composite(this, SWT.BORDER);
  
  labelHeader = new Label(compositeHeader, SWT.NONE);
  labelHeader.setText("Nazwa panelu");
  labelHeader.pack();
  formData = new FormData();
  formData.left = new FormAttachment(0, 5);
  formData.top = new FormAttachment(0, 5);
  labelHeader.setLayoutData(formData);
  
  formData = new FormData();
  formData.left = new FormAttachment(0, 0);
  formData.right = new FormAttachment(100, 0);
  formData.top = new FormAttachment(0, 0);
  compositeHeader.setLayoutData(formData);
  
  compositeContent = new Composite(this, SWT.BORDER);
  formData = new FormData();
  formData.left = new FormAttachment(0, 0);
  formData.right = new FormAttachment(100, 0);
  formData.top = new FormAttachment(compositeHeader, 0);
  formData.bottom = new FormAttachment(100, 0);
  compositeContent.setLayoutData(formData);
  compositeContent.setLayout(new FormLayout());
 }
}
 
// Creating instance
 
  FormData formData;
  
  MovablePanel panel = new MovablePanel(shell, SWT.BORDER);
  panel.setBounds(0, 0, 300, 150);
  
  Text text = new Text(panel.compositeContent, SWT.SINGLE);
  text.setText("123");
  formData = new FormData();
  formData.left = new FormAttachment(0, 5);
  formData.right = new FormAttachment(100, -5);
  formData.top = new FormAttachment(0, 5);
  formData.bottom = new FormAttachment(100, -5);
  text.setLayoutData(formData);
 
//----------------------
 
 
 
As you can see in first case it works fine, but in second case Text Control is doesn't displayed. When i try adjust Text position and size with text.setBounds(), it works, but I have to use FormLayout. I guess the reason of Control behavior is invalid use of FormData, but I can't find what's wrong.
 
Any ideas?

_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev



_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev