谁能解释为什么我在 JavaFX 中创建按钮时我的场景会失去颜色?
以下代码有效,场景背景变为红色
@Override
public void start(Stage primaryStage){
//Set Primary stage title and create a rootNode
primaryStage.setTitle("Hello World");
FlowPane rootNode = new FlowPane();
//Create a scene and add it to the rootNode
Scene myScene = new Scene(rootNode, 300, 200, Color.RED);
//Add the scene to the stage
primaryStage.setScene(myScene);
//Show the stage
primaryStage.show();
}
Run Code Online (Sandbox Code Playgroud)
但是,当我创建另一个控件时,例如下面示例中的按钮(我什至不必将其添加到流程窗格中),颜色将恢复为灰色。
@Override
public void start(Stage primaryStage){
//Set Primary stage title and create a rootNode
primaryStage.setTitle("Hello World");
FlowPane rootNode = new FlowPane();
//Create a scene and add it …Run Code Online (Sandbox Code Playgroud)