JavaFX 2.2 - 隐藏ListCell中progressIndicator的百分比

Ram*_*zan 5 css javafx-2

我有一个ListCell,其中我显示了ProgressIndicator下载文件的进度信息.

我的问题是删除指标下方显示的百分比信息.如前所述这里,我包括在我的CSS规则如下:

.customProgressIndicator .percentage{
    visibility: hidden;
    -fx-text-background-color: red;
}
Run Code Online (Sandbox Code Playgroud)

该-fx-text-background-color: red部分只是为了确保我们的css应用于节点.

问题是,我打电话indicator.setProgress(progress),百分比变得可见(红色),当我将光标悬停在指标上时,它再次变得不可见.最后,在完成调用indicator.setProgress(1.0)后,"完成"文本在底部变得可见,并在悬停后再次变为不可见.

它可能与ListView因为有关; 在悬停并使其变为不可见之后,如果我从中移除一个项目List并导致其updateItem开启ListCell,它将再次可见.

我尝试过一种解决方法:

    Text text = (Text)indicator.lookup(".percentage");
    if ( text != null )
    {
        text.setText("");
    }
Run Code Online (Sandbox Code Playgroud)

但有时候text是空的,有时候不是.

Ulu*_*Biy 10

笔记:

1)我读了你链接的帖子,OP隐含地确认了visibility: hidden;他/她的工作.但我测试了相同的代码,但它无法正常工作.可能是由于版本差异.我不知道.

2)-fx-text-background-color不是CSS属性.它是caspian.css中的预定义颜色.因此,更改它会隐式更改百分比标签的颜色,定义为默认值

.progress-indicator .percentage {
    -fx-font-size: 0.916667em; /* 11pt - 1 less than the default font */
    -fx-fill: -fx-text-background-color;
}
Run Code Online (Sandbox Code Playgroud)

caspian.css.(注意-fx-text-background-color以上)

3)最后,你想要的效果可以通过

.customProgressIndicator .percentage {
    -fx-fill: null;
}
Run Code Online (Sandbox Code Playgroud)

PS我没有在列表视图中测试进度指示器.