我有一个基于 Composite
的类,它嵌入了一个 SWT List
实例。使用默认设置,该列表在我的 WinXP 系统上有五行高。在不依赖硬编码像素值或 DPI 设置等的情况下,如何将列表(和周围的组合)的高度设置为固定的行数,比如 3,而不添加任何内边距?
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);
}
最佳答案
不能用list.getBorderWidth() 和list.getItemHeight() 来获取高度吗?
关于java - 如何在行中设置 SWT 列表的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1007819/