1

这与this几乎是同一个问题,只是略有不同。ProgressIndicator从 Java 8u45 开始,我也开始看到控件周围的边框,但只有当我选择 Caspian 的“用户代理”样式表时才能看到它们。它看起来很糟糕,但我对 Caspian 样式表非常投入,现在不愿意更改它。这是一些演示问题的代码。显然,您必须取消注释才能看到问题。

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.control.ProgressIndicator;
import javafx.stage.Stage;
import javafx.geometry.Insets;

public class ProgressIndicatorWithBorder extends Application {

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

    @Override
    public void start(Stage primaryStage) {
        // this.setUserAgentStylesheet(Application.STYLESHEET_CASPIAN);
        ProgressIndicator pi = new ProgressIndicator();
        BorderPane borderPane = new BorderPane();
        borderPane.setCenter(pi);
        borderPane.setMargin(pi, new Insets(12));
        Scene scene = new Scene(borderPane, 640, 480);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

}
4

2 回答 2

3

假设

正如提问者没有提到的那样,ProgressIndicator 可以通过两种方式使用:

  • 终止(无休止地运行)
  • 确定(从 0 到 100 计数百分比)

问题

该问题仅与inderminate state相关,因为微调器的 ProgressIndicator 样式似乎与其微调器的Datepicker样式冲突。因此 JavaFX 开发人员选择在 Java 8u40 中进行错误修复。这是对 modena.css 完成的,因为它是 JavaFX 的默认 CSS。

但在您的情况下,您想使用旧式 caspian.css。所以你必须用同样的方式来做,就像他们在这里做的那样。

Kevin Rushforth(JavaFX 人员之一)对这种行为进行了两张截图:

ProgressIndicator-坏

ProgressIndicator-Bad.png

ProgressIndicator-良好

ProgressIndicator-Good.png

解决方案

制作自己的样式表文件。我打电话给我的 pibug.css。将其设置在 ProgressIndicator 上,因为它是样式表。这不会覆盖caspian.css 中已设置的其他默认值。

pibug.css

.progress-indicator:indeterminate > .spinner {        
    -fx-background-color: transparent;
    -fx-background-insets: 0;
    -fx-background-radius: 0;
}

但这还不是全部,如果你想让你的Datepicker与 caspian.css 一起工作,你需要在你的 Datepicker 上设置以下样式:

dpbug.css

.date-picker-popup > * > .spinner {
    -fx-spacing: 0.25em; /* 3 */
    -fx-alignment: CENTER;
    -fx-fill-height: false;
    -fx-background-color: transparent; /* this line was added */
}
于 2015-06-23T16:55:41.437 回答
1

我们必须从以下位置复制部分modena.css

.progress-indicator:indeterminate > .spinner {
    /** Applying to undo styling from .spinner, reported in RT-37965 */
    -fx-background-color: transparent;
    -fx-background-insets: 0;
    -fx-background-radius: 0;
}

它不需要修改。

(注意:NwDX 的答案很有用,因为它让我指出了正确的方向,所以我试图将这个事实编辑到他的答案中。但我的编辑被拒绝了,因为它偏离了原始答案的意图。)

于 2015-06-23T22:32:13.593 回答