【发布时间】:2019-02-15 20:54:01
【问题描述】:
我需要了解如何显示由 Main javaFX 应用程序加载的 FXML 文件中插入的元素,我的 JavaFX 应用程序主要是:
// imports omitted
public class Main extends Application {
@Override
public void start(Stage window) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("Standard.fxml"));
Scene mainGraphic = new Scene(root,500,500);
window.setTitle("Prova con FXML");
window.setMinHeight(500);
window.setMinWidth(500);
window.setScene(mainGraphic);
window.show();
}
}
这个文件可以正常加载FXML文件Standard.fxml,问题是它没有显示顶部矩形,这是FXML文件:
// imports omitted
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.myname.mypackage.Controller">
<stylesheets>
<URL value="@Standard.css"/>
</stylesheets>
<Rectangle id="ParteSuperiore"/>
</AnchorPane>
我显然已经创建了 CSS 文件并使用我想要的属性对元素进行了样式化,这就是 CSS:
#AnchorPane {
-fx-background-color: rgb(224, 246, 255);
}
#ParteSuperiore {
-fx-fill: rgb(255, 145, 28);
-fx-arc-height: 100px;
-fx-arc-width: 100px;
}
这个文件有什么问题?我只能看到 AnchorPane 的背景颜色!我试图将Rectangle 放在<children> 元素中,但是我继续只看到AnchorPane 的背景颜色,而看不到矩形!我应该使用区域而不是矩形吗?如果是,我怎样才能给它宽度和高度?在JavaFX CSS reference 中,它没有给我设置宽度和高度的指令,比如矩形的-fx-arc-height。
【问题讨论】: