gpt4 book ai didi

java - 文本对象拒绝改变颜色,尽管 CSS 指令这样做

转载 作者:行者123 更新时间:2023-11-29 07:51:20 24 4
gpt4 key购买 nike

尽管在设置文本之前设置了 id,但事件处理程序之前的代码中的文本对象没有改变颜色。但是,文本将随着文本集填充而改变颜色。我很好奇的一件事是,在 CSS 中,颜色不会随着 .text{}#Sign-In-Text{} 而改变。我只是不正确地使用了 CSS 吗?

Java 代码:

public class CSSTrial1 extends Application {

@Override
public void start(Stage stage) throws Exception {
stage.setTitle("CSS Trial");
stage.setResizable(false);
final GridPane grid = new GridPane();
ColumnConstraints constraints = new ColumnConstraints();
grid.getColumnConstraints().add(constraints);
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25));
grid.add(new Label("Character Name:"), 0, 0);
final TextField nameField = new TextField("");
nameField.setPromptText("Randel James");
grid.add(nameField, 1, 0);
grid.add(new Label("Weapon:"), 0, 1);
final ComboBox<String> weapons = new ComboBox<>();
weapons.getItems().addAll("Katsuragi x2", "Assault Rifle",
"Pistol", "RPG-7", "Barret 50. Cal");
grid.add(weapons, 1, 1);
HBox box = new HBox(10);
box.setAlignment(Pos.BOTTOM_RIGHT);
Button submit = new Button("Submit Character");
final Text text = new Text();
text.setId("Sign-In-Text");
submit.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
text.setText("Signed In As: " + nameField.getText()
+ ", Weapon: " + weapons.getValue());
//text.setWrappingWidth(100);
}
});
//text.setFill(Color.ROYALBLUE);
grid.add(text, 0, 6);
box.getChildren().add(submit);
grid.add(box, 1, 3);
Scene scene = new Scene(grid, 300, 275);
scene.getStylesheets().add(CSSTrial1.class.getResource("CSSTrial1Style.css")
.toExternalForm());
stage.setScene(scene);
stage.show();
}

}

CSS:

.root{
-fx-background-color: #710ad1;
}
.label{
-fx-text-fill:#11d30b;
-fx-font: bold 13pt fantasy;
}
.text{
-fx-text-fill:#11d30b;
-fx-font: bold 13pt fantasy;
}
#custom-text{
-fx-font: 16px "Serif";
-fx-padding: 10;
-fx-background-color: #CCFF99;
}
#Sign-In-Text{
-fx-text-fill:#11d30b;
-fx-font: bold 10pt fantasy;
}

最佳答案

尝试:

-fx-fill: #11d30b; 

代替:

-fx-fill-text: #11d30b;

文档中的示例:http://docs.oracle.com/javafx/2/text/jfxpub-text.htm#CHDDAEBG

另请查看此处的类似问题:JavaFX TableView: Cannot Override '-fx-text-fill'!

关于java - 文本对象拒绝改变颜色,尽管 CSS 指令这样做,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20916065/

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