【问题标题】:JavaFx TableView ProgressBar with Conditional Color change具有条件颜色更改的 JavaFx TableView ProgressBar
【发布时间】:2019-01-17 19:20:58
【问题描述】:

需要: 能够在多线程程序中根据条件改变TableView中ProgressBar的颜色

研究: 我参考了链接 - Link1,据此我可以在 TableView 中设置由多个线程更新的 ProgressBar。根据链接 - Link2 我需要能够更改颜色。此外,谷歌搜索也是如此,但无法使其正常工作并因此发布。

问题: 我已经完成了绑定和更新属性,但它似乎不起作用。进度条会根据值更新,这很好。

无法弄清楚如何根据条件更改颜色。希望所面临的问题很清楚,非常感谢您的意见/指导。

代码(Controller 类的相关部分):

    StringProperty colorProperty = new SimpleStringProperty();
    .
    .
    .
    progressBar.setCellValueFactory(new PropertyValueFactory<>("pBar));
    progressBar.setCellFactory(ProgressBarTableCell.forTableColumn());
    // Bind property for progress Bar Color Change
    progressBar.styleProperty().bind(colorProperty);
    .
    .
    .
    private static void updateTableView(List<TableViewCust> list, ModelDataFeed apiDataFeed) {
            list.forEach(e -> {
                double pBarValue = ((apiDataFeed.getMax() - apiDataFeed.getMin()) / e.getAvg());
                e.setProgressBar(pBarValue / 5);
                setProgressBarColor(pBarValue / 5));
            });
        }
    .
    .
    .
    // Set Colour to Progress Bar
    private static void setProgressBarColor(double pBarValue) {
            if (pBarValue <= 0.2) {
                colorProperty.setValue("-fx-accent: lightskyblue");
            } else if (pBarValue <= 0.4) {
                colorProperty.setValue("-fx-accent: palegreen");
            } else if (pBarValue <= 0.6) {
                colorProperty.setValue("-fx-accent: orange");
            } else if (pBarValue <= 0.8) {
                colorProperty.setValue("-fx-accent: orchid");
            } else {
                colorProperty.setValue("-fx-accent: red");
            }
        }

【问题讨论】:

    标签: java javafx tableview progress-bar


    【解决方案1】:

    不知道为什么我的问题被否决了,尽管遵守了规则。

    无论如何,经过进一步的试验设法让它工作,如果有人在寻找类似的东西,你需要做的就是扩展 - TableCell&lt;S, Double&gt; 并通过覆盖 ProgressBarTableCell 的 updateItem(Double item, boolean empty) 方法来合并所需的配色方案

    【讨论】:

      猜你喜欢
      • 2012-11-01
      • 2012-11-08
      • 2017-01-06
      • 1970-01-01
      • 2013-02-20
      • 2016-01-30
      • 1970-01-01
      • 1970-01-01
      • 2019-05-26
      相关资源
      最近更新 更多