java - 如何设置SWT表的表头高度?

标签 java swt tableheader

目前,我在设置表格标题的高度时遇到一些问题。这是我的代码:

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    final Table table = new Table(shell, SWT.H_SCROLL | SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION | SWT.CHECK);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    final String[] titles = { "titleioioio", "C", "!", "Description", "Resource", "In Folder", "Location" };
    for (int i = 0; i < titles.length; i++) {
        TableColumn column = new TableColumn(table, SWT.NONE);
        column.setText(titles[i]);
    }

    int count = 10;
    for (int i = 0; i < count; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(0, "x");
        item.setText(1, "y");
        item.setText(2, "!");
        item.setText(3, "this stuff behaves the way I expect");
        item.setText(4, "almost everywhere");
        item.setText(5, "some.folder");
        item.setText(6, "line " + i + " in nowhere");
    }
    table.pack();
    for (int i = 0; i < titles.length; i++) {
        table.getColumn(i).pack();
    }
    Button button = new Button(shell, SWT.PUSH);
    button.setText("change font");
    button.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            FontDialog d = new FontDialog(shell);
            FontData data = d.open();
            table.setFont(new Font(display, data));
            for (int i = 0; i < titles.length; i++) {
                table.getColumn(i).pack();
            }

        }

        public void widgetDefaultSelected(SelectionEvent e) {

        }
    });

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

有什么办法可以设置这个表头的高度吗?我尝试在 TableTableColumn 中找到 setSize() 方法,但它不存在。

最佳答案

无法更改 SWT 表或树中标题的高度。

SWT 使用底层平台的 native 小部件,在某些情况下不允许更改标题高度。为了在所有平台上保持一致,SWT 不提供 API。

关于java - 如何设置SWT表的表头高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41227483/

相关文章:

java - 在 Windows 上的 Spark-Submit 中将多个 -D 参数传递给 driver-java-options

java - 覆盖 VK_Tab 焦点操作

java - 执行 API 测试时忽略证书

java - 使用向导和 ScrolledForm(jface 和 forms api)

javascript - jquery 增加最后一个

javascript - 如何删除 angular-ui-grid 列标题中的 "clear sort"状态?

javascript - 粘性表不适用于引导模式中的表

java - 具有中间证书的 Android SSL 信任链 (Apache HttpClient 4.X)

swt - 测量 SWT/JFace 列标题填充大小

java - 是否可以在标题阅读对话框的底部添加消息栏/工具栏?