• Post Reply Bookmark Topic Watch Topic
  • New Topic

2 Composites in 1 - how to set their sizes? (RCP application)  RSS feed

 
Ismael Upright
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a View, in which I put a Composite A with the size of View.

Now I would like to insert into Composite A two other Composites: B and C, but I want Composite B to take 2/3 of width of Composite A, and Composite C to take 1/3 of width of Composite A, independently of the application window size. Anyone knows how to do it?


//Composite A:
Composite mainComposite = new Composite(parent, SWT.NONE);
GridData mainLayoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
mainLayoutData.horizontalSpan = 1;
mainComposite.setLayoutData(mainLayoutData);
GridLayout mainLayout = new GridLayout(3, false);
mainLayout.marginWidth = 0;
mainLayout.marginHeight = 0;
mainComposite.setLayout(mainLayout);

//Composite B:
Composite subCustomerComposite = new Composite(mainComposite, SWT.NONE);
GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
layoutData.horizontalSpan = 1;
subCustomerComposite.setLayoutData(layoutData);
GridLayout layout = new GridLayout(2, false);
subCustomerComposite.setLayout(layout);

//Composite C:
Composite subCustomerComposite2 = new Composite(mainComposite, SWT.NONE);
GridData layoutData2 = new GridData(SWT.FILL, SWT.FILL, true, true);
layoutData2.horizontalSpan = 1;
subCustomerComposite2.setLayoutData(layoutData2);
GridLayout layout2 = new GridLayout(1, false);
subCustomerComposite2.setLayout(layout2);
 
Ismael Upright
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind, I resolved it at another forum.

I added the listener:

A.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
Composite composite = (Composite) e.widget;
int width = composite.getBounds().width;
((GridData) B.getLayoutData()).widthHint = (int) (0.66 * width);
((GridData) C.getLayoutData()).widthHint = (int) (0.33 * width);
}
});
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!