SWT树表:在Mac上无法更改标题的字体大小

时间:2018-07-19 09:01:03

标签: java eclipse tree swt

enter image description here我尝试了以下代码来更改Java中树形表头的字体大小。 它适用于Windows,但不适用于Mac。任何解决方案/原因为何在Mac上无法使用?

代码:

public class TreeClass { 
    public static final int GROUP_ITEM = 1 << 1;
    public static final int SOURCE_LIST = 1 << 30;
    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());

        final Tree tree = new Tree (shell, SOURCE_LIST);
        tree.setFont(new Font(display,"", 14, SWT.NONE));
        tree.setLinesVisible(true);
        tree.setHeaderVisible(true); 

        TreeColumn tableColumn1 = new TreeColumn(tree, SWT.BOLD);
        tableColumn1.setText("User");
        tableColumn1.setWidth(280);
        TreeColumn tableColumn2 = new TreeColumn(tree, SOURCE_LIST);
        tableColumn2.setText("Visited");
        tableColumn2.setWidth(150);
        TreeColumn tableColumn3 = new TreeColumn(tree, SOURCE_LIST);
        tableColumn3.setText("Vist Date");
        tableColumn3.setWidth(150);
        TreeColumn tableColumn4 = new TreeColumn(tree, SOURCE_LIST);
        tableColumn4.setText("Login ID");
        tableColumn4.setWidth(150);
        TreeColumn tableColumn5 = new TreeColumn(tree, SOURCE_LIST);
        tableColumn5.setText("Data");
        tableColumn5.setWidth(150);
        TreeColumn tableColumn6 = new TreeColumn(tree, SOURCE_LIST);
        tableColumn6.setText("Priority");

        for (int i=0; i<4; i++) {
            final TreeItem iItem = new TreeItem (tree, GROUP_ITEM);
            display.asyncExec( new Runnable() {
                public void run() {
                    iItem.setExpanded(true);
                }
            });
            iItem.setText ("GROUP " + i);
            for (int j = 0; j < 4; j++) {
                TreeItem jItem = new TreeItem (iItem, 0);
                jItem.setText ("TreeItem " + j);
            }
        }

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

}

以上代码在Windows上具有更改的字体大小。但是在Mac上它不起作用。

0 个答案:

没有答案