[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: How to trigger re-layout of form (same as what resizing the window does)

Mike Yawn wrote:
I've spent hours on this, and the behavior seems completely random to me. Hoping someone can clue me in on the magic incantation.

I have a form where the left hand side has a tree, and the content of the right-hand side varies depending on the tree selection. Regardless of what is selected in the tree, the width of the form shouldn't change, so everything should get laid out on the right side to fill the available space.

Everything uses GridLayout, and all GridDatas are set to fill horizontal.

When I change the tree selection, sometimes the components are drawn correctly and exactly fill the available space. Sometimes they aren't wide enough (fill horizontal seems to be ignored) leaving excess white space, and sometimes they are too wide (so they extend beyond the page boundaries).

However, if I resize the window, everything snaps to exactly the right size. This seems to me to indicate that all of my layout, griddata, etc. stuff is right, and that the layout just isn't being re-calculated as needed when a tree selection changes.

So I've tried calling pack, layout, reflow, getParent.pack, getParent.layout(true, true), calling these various calls on many different combinations of the form, the body of the form, the composite for the right side of the form, individual components -- nothing seems to work.

Most likely you need to call layout() on the top-level Composite [probably the ScrolledForm that you get from managedForm.getForm()].
As Matthew suggested, a code snippet would help a great deal here.


I'll also mention the class org.eclipse.ui.forms.MasterDetailsBlock which implements the UI pattern that you are describing - you might want to look into it as an alternative to your own home-grown implementation.

Eric