Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaFX:调整窗口大小时标签会更改位置_Java_Label_Fxml_Borderpane - Fatal编程技术网

JavaFX:调整窗口大小时标签会更改位置

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

我有一个非常简单的标签,在父对象中添加了文本“Hello World”,我想将其添加到BorderPane的中间

标签开始时有点偏离中心,当调整窗口大小时,标签/父项“捕捉”到我想要的位置。为什么会这样

FXML类:

<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);
}
}