Question

I am writing an Eclipse plugin which has a hover control that consists of two controls, one on top of another:

An HTML viewer (BrowserInformationControl) for which I Can easily compute the size hint

A TreeViewer that contains a Tree.

I have set up my tree with actual contents. However, I can't find a way to figure out the size of the tree or the size hint for it once rendered.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top