【问题标题】:How to display white text with a black background?如何显示黑色背景的白色文本?
【发布时间】:2019-07-04 00:59:06
【问题描述】:

我想弄清楚为什么我的文字没有显示在这里。我认为它不是白色的,根本不会出现在黑色背景上。所以,我想弄清楚为什么背景是黑色的,但没有显示文本。

我正在使用 JavaFX 12。

如何将字母涂成白色?

public class MCVE extends Application {

private static Stage gameStage = new Stage();

@Override
public void start(Stage primaryStage) {

   gameStage.setScene(new Scene(createScreen(), 1280.0, 800.0));

   // adjust window settings.
   gameStage.setTitle("my game");
   gameStage.setResizable(false);

   gameStage.show();
}

private Pane createScreen() {

   Text welcome = new Text("Welcome,");
   welcome.setFont(new Font("Old_Style", 22.0));
   welcome.setStyle("-fx-text-fill: whitesmoke");

   Text toMyGame = new Text(" to my game.");
   toMyGame.setFont(new Font("System", 14.0));
   toMyGame.setStyle("-fx-text-fill: whitesmoke");

   TextFlow tf = createTextFlow();
   ObservableList list = tf.getChildren();

   list.addAll(welcome, toMyGame);

   return tf;
}

private TextFlow createTextFlow() {

   String style = "-fx-background-color: black;";
   style += " -fx-text-fill: whitesmoke;";

   TextFlow tf = new TextFlow();
   tf.setStyle(style);

   return tf;
}

}

【问题讨论】:

    标签: java css javafx text textflow


    【解决方案1】:

    -fx-text-fillis a CSS property of Labeled,不是文本。文本是一种形状,Shape supports -fx-fill 而不是 -fx-text-fill。

    将每次出现的-fx-text-fill 更改为-fx-fill 应该会给您想要的外观。

    【讨论】:

    • 谢谢!我从来没有考虑过。
    猜你喜欢
    • 2015-08-09
    • 2017-04-23
    • 2011-01-16
    • 2010-11-22
    • 2019-12-13
    • 2017-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多