【发布时间】:2015-03-20 13:29:24
【问题描述】:
我正在学习 JavaFx,我正在尝试在运行时更改我的窗口(Mastermind 游戏)的 css 样式。
目前它适用于一些对象,如按钮、背景、菜单栏、标签和形状。 但我想更改的另一个对象是菜单项(背景和标签)。
我尝试使用下一个 css 代码来访问它:
.context-menu {
-fx-background-color: linear-gradient(rgba(200,200,200,1),rgba(50,50,50,1) 80%);
}
它在初始化时起作用,但在运行时更改时不起作用。 例如,它适用于菜单栏本身:
.menu-bar {
-fx-background-color: black;
-fx-selection-bar: #505050;
}
.menu-bar .label {
-fx-font-size: 12pt;
-fx-font-family: "Segoe UI Light";
-fx-text-fill: white;
-fx-opacity: 0.9;
}
在 FXMLcontroller 中,我调用以下代码来更改皮肤:
@FXML private AnchorPane generalPane;
private final String themeNormal = getClass().getResource("/mastermindStyles/MasterMind_Normal.css").toExternalForm();
@FXML
void handleSkinNormal(ActionEvent event){
generalPane.getStylesheets().clear();
generalPane.getStylesheets().add(themeNormal);
}
我该怎么做?
【问题讨论】:
标签: css javafx runtime menuitem fxml