需要使用XML数据在javafx中自定义组合框 [英] Need to customize combobox in javafx with xml data

查看:105
本文介绍了需要使用XML数据在javafx中自定义组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要显示带有从XML文件读取的值的javafx树表。我能够做到如下所示,

I need to display the javafx tree table with values read from XML file. I am able to do it as shown below,

我能够如图所示向组合框添加颜色

I am able to add color to the combo box as shown

但是当我折叠树时,设置的颜色仍然保持不变,如此处所示

But when I collapse the tree the color which is set still remains the same, as shown here

如何将其恢复为正常?

这是我尝试更改的代码组合框
的颜色,其中 dojColumn 是显示状态的列

This is the piece of code I tried for changing color to the combobox where dojColumn is a column to display "Status"

dojColumn.setCellFactory(new Callback<TreeTableColumn<TestSet, String>, TreeTableCell<TestSet, String>>(){

    @Override
    public TreeTableCell<TestSet, String> call(TreeTableColumn<TestSet, String> param) {
        // TODO Auto-generated method stub

        return new ComboBoxTreeTableCell<TestSet,String>(list){

            public void updateItem(String status,boolean empty) {
                super.updateItem(status, empty);
                 int currentIndex = indexProperty().getValue() < 0 ? 0: indexProperty().getValue();
                String clmStatus = dojColumn.getCellData(currentIndex);
                if(!empty) {
                    if (status == null || empty) {
                        setStyle("");
                    }
                    else if (clmStatus.equals("Passed")) {
                        setTextFill(Color.BLACK);
                        //setStyle("-fx-font-weight: bold");
                        setStyle("-fx-background-color: green");
                        setText(clmStatus);

                    } else if (clmStatus.equals("Failed")){
                        setTextFill(Color.BLACK);
                        //setStyle("-fx-font-weight: bold");
                        setStyle("-fx-background-color: red");
                       setText(clmStatus);
                    } else if (clmStatus.equals("NotRelevant")){
                        setTextFill(Color.BLACK);
                       // setStyle("-fx-font-weight: bold");
                        setStyle("-fx-background-color: blue");
                      setText(clmStatus);
                    } 
                }
            }
        };
    }

});

有人可以帮我吗?提前致谢。

can anyone help me with this. Thanks in advance.

推荐答案

您的问题似乎在您的更新项目中。

Your issue seems to be in your update item.

您正在检查它是否不为空,然后如果为空,则设置回 ...

You are checking that it's not empty, then if empty set back to ""...

if(!empty) {
    if (status == null || empty) {
         setStyle("");
    }
    etc...

只需取下外部支票-您不要不是我们的 if(!empty){}

Just remove the outer check - you don't the our if(!empty){}

只需使用此:

if (status == null || empty) {
   setStyle("");
}
else if (clmStatus.equals("Passed")) {
    setTextFill(Color.BLACK);
    setStyle("-fx-background-color: green");
    setText(clmStatus);
} else if (clmStatus.equals("Failed")){
    setTextFill(Color.BLACK);
    setStyle("-fx-background-color: red");
    setText(clmStatus);
} else if (clmStatus.equals("NotRelevant")){
    setTextFill(Color.BLACK);
    setStyle("-fx-background-color: blue");
    setText(clmStatus);

}

这篇关于需要使用XML数据在javafx中自定义组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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