在Javafx中为treetableview的列标题设置工具提示 [英] Set Tooltip for column header of treetableview in Javafx

查看:724
本文介绍了在Javafx中为treetableview的列标题设置工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有动态TreeTable。如何为列标题设置工具提示,列标题显示标题文本。下面的代码显示了特定单元格的工具提示,但我不知道在哪里为标题文本设置它。

I have dynamic TreeTable. how can i set tooltip for column header, which shows the header text. The code bellow shows tooltip for specific cells, but i do not know where to set it for header text.

    for (Entry<String, String> ent : dc.getSortedAssignedOrg().entrySet()) {

        TreeTableColumn<String, ArrayList<String>> col = new TreeTableColumn<>(
                ent.getValue());
col.setCellFactory(new Callback<TreeTableColumn<String, ArrayList<String>>, TreeTableCell<String, ArrayList<String>>>() {
            @Override
            public TreeTableCell<String, ArrayList<String>> call(
                    TreeTableColumn<String, ArrayList<String>> param) {
                return new TreeTableCell<String, ArrayList<String>>() {
                    public void updateItem(ArrayList<String> item,
                            boolean empty) {
                        super.updateItem(item, empty);


                        if (item == null || empty) {
                            setStyle("");
                            setText("");
                        } else if (item.contains("Green")) {
                            float weightInt = Float.parseFloat(item.get(0));
                            float res = weightInt * 1;
                            String resString = Float.toString(res);
                            this.setStyle("-fx-background-color:green");
                            setTooltip(new Tooltip(item.get(2)));
                            setText(resString);
                        } else if (item.contains("yellow")) {
                            this.setStyle("-fx-background-color:yellow");
                            setTooltip(new Tooltip(item.get(2)));
                            setText("0");
                        } else if (item.contains("white")) {
                            setText("DD");
                        }
                    }
                };
            };

        });

        treeTableView.getColumns().add(col);

}

推荐答案

不是为列设置文本,而是创建 Label 并将其设置为列的图形。然后在标签上设置工具提示。

Instead of setting text for the column, create a Label and set it as the graphic for the column. Then set the tooltip on the label.

I.e。而不是

    TreeTableColumn<String, ArrayList<String>> col = new TreeTableColumn<>(
            ent.getValue());

do

    TreeTableColumn<String, ArrayList<String>> col = new TreeTableColumn<>();
    Label label = new Label(ent.getValue());
    col.setGraphic(label);
    label.setTooltip(new Tooltip("Tooltip text goes here"));

这篇关于在Javafx中为treetableview的列标题设置工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆