JavaFX:从ProgressIndicator中删除百分比

时间:2017-03-10 09:26:37

标签: java css javafx javafx-8

我一直在尝试删除ProgressIndicator下面的百分比文本,但是不成功。我已经找到了几个这样的提及并尝试了接受的答案,但它不起作用

使用Java 8 Update 121

package com.company.mytest;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class ProgressApp extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    /* (non-Javadoc)
     * @see javafx.application.Application#start(javafx.stage.Stage)
     */
    @Override
    public void start(Stage stage) throws Exception {
        ProgressIndicator progress = new ProgressIndicator();
        progress.setProgress(0.5f);

        StackPane root = new StackPane();
        root.getChildren().add(progress);

        Scene scene = new Scene(root);

        scene.getStylesheets()
        .add(getClass().getResource("progress.css").toExternalForm());

        stage.setScene(scene);
        stage.setWidth(300);
        stage.setHeight(300);
        stage.setTitle("JavaFX 8 app");
        stage.show();
    }

}

我知道CSS已加载,因为我可以更改字体百分比大小。这是progress.css文件的CSS内容。

.progress-indicator .percentage {
    visibility: hidden;
}

1 个答案:

答案 0 :(得分:2)

-fx-fill属性设置为null似乎可以解决问题:

.progress-indicator .percentage {
   -fx-fill:null;
}

<强>更新

仅设置此属性会隐藏文本百分比,但仍会占用空间。

可能的解决方法是设置-fx-padding的<{1}}属性:

ProgressIndicator

唯一的问题是硬编码值:如果.progress-indicator .percentage { -fx-fill:null; } .progress-indicator { -fx-padding: 0 0 -16 0; } 的CSS被更改(例如更大的字体大小),那么这也必须进行调整。

此答案中的程序化解决方案:How can I avoid the display of percentage values, when using the ProgressIndicator of JavaFX UI Controls

相关问题