gpt4 book ai didi

JavaFX:从 ProgressIndicator 中删除百分比

转载 作者:行者123 更新时间:2023-11-30 02:37:19 26 4
gpt4 key购买 nike

我一直在尝试删除 ProgressIndicator 下面的百分比文本,但没有成功。我发现了几次对此的提及并尝试了接受的答案,但它不起作用

使用 Java 8 更新 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;
}

最佳答案

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

.progress-indicator .percentage {
-fx-fill:null;
}
<小时/>

更新:

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

一个可能的解决方法是设置 ProgressIndicator-fx-padding 属性:

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

.progress-indicator {
-fx-padding: 0 0 -16 0;
}

唯一的问题是硬编码值:如果 .progress-indicator .percentage 的 CSS 发生更改(例如更大的字体大小),那么也必须进行调整。

<小时/>

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

关于JavaFX:从 ProgressIndicator 中删除百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42714744/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com