According to the API of org.eclipse.swt.widgets.Tree, this should be done with:
public Point computeSize(int wHint,
int hHint,
boolean changed)
The preferred size of a control is the size that it would best be displayed at.
The width hint and height hint arguments allow the caller to ask a control questions such as "Given a particular width, how high does the control need to be to show all of the contents?"
To indicate that the caller does not wish to constrain a particular dimension, the constant SWT.DEFAULT is passed for the hint.
If the changed flag is true, it indicates that the receiver's contents have changed, therefore any caches that a layout manager containing the control may have been keeping need to be flushed. When the control is resized, the changed flag will be false, so layout manager caches can be retained.
Note that on Windows, the behavior of computeSize()
was flawed: see this message and this bug: fixed for eclipse 3.4M1 and forward.
Example of use of computeSize()
in this message.
The use of getBound()
might be another interesting alternative.