How to update view size when new widgets are added? [message #488111] |
Fri, 25 September 2009 11:18  |
Eclipse User |
|
|
|
Dear All,
I encountered a layout size issue with PageBook. Here is the widgets in my views:
UI form view:
-------------------------
Table1
PageBook1
Table1 has 10 items. When a table item is selected, PageBook1 shows relative page control. The page controls are in different sizes. Therefore it means that PageBook1 needs to change size and update its view part. How can I achieve this?
I have tried to call form.reflow(true), but the PageBook size remains a single row.
Thank you so much! Have a nice weekend!
Regards,
Frank
|
|
|
|
Re: How to update view size when new widgets are added? [message #488194 is a reply to message #488111] |
Fri, 25 September 2009 16:36  |
Eclipse User |
|
|
|
Finally I figure it out. Below is the code snippet for someone who is interested in it. Please note: the last 4 statements are very important. They will do:
1. compute desired size for the widget
2. update the layout data
3. call layout() on the widget
4. reflow the form view
myTable.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
Composite parent = toolkit.createComposite(pageBook);
parent.setLayout(new GridLayout(1, false));
int index = myTable.getSelectedIndex();
MStep step = .....
for(int i=0; i<(index+1)*5; i++){
toolkit.createLabel(parent, "hello world: " + step.getName());
toolkit.createText(parent, "text to be added: " + step.getConfigId());
}
pageBook.showPage(parent);
Point computeSize = pageBook.computeSize(SWT.DEFAULT, SWT.DEFAULT);
GridDataFactory.defaultsFor(pageBook).align(SWT.FILL, SWT.TOP).span(2, 1).hint(SWT.DEFAULT, computeSize.y + 50).applyTo(pageBook);
pageBook.layout(true, true);
form.reflow(true);
}
});
Regards,
Frank Du
------------------
Blogs about RCP: http://www.frankdu.com/weblog
|
|
|
Powered by
FUDForum. Page generated in 0.07240 seconds