4
我有一个基于Composite
的课程,它嵌入了一个SWT List
实例。使用默认设置,我的WinXP系统上的列表为五行。不依赖硬编码的像素值或DPI设置等,我怎样才能将列表(和周围组合)的高度设置为固定行数(例如3),而不增加内部边距?如何在行中设置SWT列表的高度?
public FileSetBox(Composite parent, int style)
{
super(parent, style);
setLayout(new FillLayout());
this.list = new List(this, SWT.V_SCROLL);
...
}
更新:
以下的作品,但它并没有考虑到边境,导致最后一行的部分被覆盖增加的高度。任何想法如何计算呢?
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);
}
愚蠢的我......这很明显,我忽略了它。非常感谢 :-) – 2009-06-18 06:28:16