Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsQuestion: Correct implementation of complex component layout
https://www.eclipse.org/forums/index.php/mv/msg/783839/1389219/#msg_1389219
I'm now reviewing my older code written in pure SWT+jFace and I can't get it to re-layout correctly after some changes. The thing is that I can't seem to figure out how to correctly layout component hierarchy after some children component has been changed and its preferred size has potentially changed (child.computeSize(SWT.DEFAULT, SWT.DEFAULT)).
What is the correct way to implement such bottom->up re-layout?
My approach was this but does not always work as intended:
Throughout my code I used custom implementation of LayoutListeners that I implemented in my base class for CustomComposite.
@Override
public void layout() {
// Simplified version
for (LayoutListener l : layoutListeners) l.beforeLayout();
super.layout();
for (LayoutListener l : layoutListeners) l.afterLayout();
}
By registering such layout listener I can be notified of when the children component requests layout and can effectively layout its parent.
But this approach has a few setbacks:
- It sometimes requires more passes to be laid-out correctly: child component is firstly laid-out in boundaries that it previously obtained from the parent layout and then it has to be laid-out again after parent component has determined its preferred_size).
- And sometimes it does not work at all (and due to lack of scriptability for Java, debugging is really painful).
Please advise on correct approach. I hope that I'm not the only one that would benefit from such knowledge.]]>Tomas R.2014-06-27T14:00:26-00:00Re: Question: Correct implementation of complex component layout
https://www.eclipse.org/forums/index.php/mv/msg/783839/1389239/#msg_1389239
I just hope, that this post will not end with 0 replies and 2k> views like the others in the forum. :/]]>Tomas R.2014-06-27T14:30:43-00:00