java - 如何在行中设置 SWT 列表的高度?

标签 java swt

我有一个基于 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/

相关文章:

java - 连接和读取图像字节和字符串字节

java - 有什么方法可以使用 Eclipse 在 Java 字符串文字中编写(复制粘贴)格式良好的 SQL 查询?

java - 使用通过 PHP 从 Android 应用程序插入的数据连接到 PostgreSQL 数据库时出错

java - 在 Eclipse/RCP 中定位工具栏

java - 在 Windows 上的 Eclipse RCP 应用程序中使用时如何禁用 swt 浏览器点击声音?

java - 将文件从文件阵列复制到目录

java - Jetty 9 托管具有多个 SSL 证书的多个虚拟主机

MacOS 上的 Eclipse : SWT lib code signature not valid for use in process using Library Validation

java - org.eclipse.jface.viewers.TreeViewer 不显示任何内容

java - 如何以编程方式在comboviewer中设置所需的选择