tags:

views:

916

answers:

1

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.

+2  A: 

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.

VonC
That is what I have been using... Unfortunately, it does not seem to impress Eclipse, which keeps returning too small a point...
Uri
Hi VonC, thanks for the help with this.It turns out that the problem only occurs on the Mac version. When I run it in windows, my code works like a charm. I am going to check with the other Mac distribution, since they have two different UI systems that they use.
Uri
@Uri: good to know. I will check if there is a current eclipse bug registered for that.
VonC