I have a class based on Composite
that embeds an SWT List
instance. Using the default settings, the list is five rows high on my WinXP system. Without relying on hard-coded pixel values or DPI settings and the like, how can I set the height of the list (and the surrounding composite) to a fixed number of rows, say 3, without any added inner margins?
public FileSetBox(Composite parent, int style)
{
super(parent, style);
setLayout(new FillLayout());
this.list = new List(this, SWT.V_SCROLL);
...
}
Update:
The following works, but it does not take into account the height added by the border, which results in parts of the last line being covered. Any ideas how to calculate this, too?
public FileSetBox(Composite parent, int style)
{
...
GC gc = new GC(this);
gc.setFont(this.list.getFont());
this.preferredHeight = gc.getFontMetrics().getHeight() * 3;
gc.dispose();
...
}
@Override
public Point computeSize(int arg0, int arg1)
{
Point size = super.computeSize(arg0, arg1);
return new Point(size.x, this.preferredHeight);
}