JavaFX:调整窗口大小时标签会更改位置
我有一个非常简单的标签,在父对象中添加了文本“Hello World”,我想将其添加到BorderPane的中间 标签开始时有点偏离中心,当调整窗口大小时,标签/父项“捕捉”到我想要的位置。为什么会这样 FXML类:JavaFX:调整窗口大小时标签会更改位置,java,label,fxml,borderpane,Java,Label,Fxml,Borderpane,我有一个非常简单的标签,在父对象中添加了文本“Hello World”,我想将其添加到BorderPane的中间 标签开始时有点偏离中心,当调整窗口大小时,标签/父项“捕捉”到我想要的位置。为什么会这样 FXML类: <BorderPane fx:id="pane" fx:controller="sample.Controller" xmlns:fx="http://javafx.com/fxml"> <center> <MapCan
<BorderPane fx:id="pane" fx:controller="sample.Controller"
xmlns:fx="http://javafx.com/fxml">
<center>
<MapCanvas fx:id="map" BorderPane.alignment="CENTER"/>
</center>
</BorderPane>
通用JavaFX主类:
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Model model = new Model();
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 300));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
您为什么要扩展父级?除非您有很好的理由,否则扩展布局窗格可能是错误的,但即使您这样做了-为什么不
Group
或pane
?将来我希望能够绘制地图,并且我正在寻找JavaFX JComponent的替代品。
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Model model = new Model();
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 300));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}