[英]JavaFX - Issue when including another fxml to a border pane center of a main fxml
I'm trying to include an additional fxml in a main fxml, border pane center. 我正在尝试在主fxml(边框窗格中心)中包含其他fxml。 When I do this, the fxml gets included and shows in the center, but the fxml does not occupy the full width and height of the main fxml window.
当我这样做时,fxml被包括在内并显示在中央,但是fxml不会占据fxml主窗口的全部宽度和高度。
In the SceneBuilder, if I add the TableView in the center of the borderpane, it acts as it should. 在SceneBuilder中,如果我在边框窗格的中央添加TableView,它将按应有的作用。 Only when I include the fxml via code it does not.
只有当我通过代码包含fxml时,才不会。
Please help, what am I missing? 请帮忙,我想念什么? Any help will be appreciated!
任何帮助将不胜感激!
This is what I need: 这就是我需要的:
This is what I get:
这是我得到的:
Main FXML:
主要FXML:
<?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.effect.*?> <?import javafx.geometry.*?> <?import javafx.scene.control.*?> <?import java.lang.*?> <?import javafx.scene.layout.*?> <TabPane fx:id="TabPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="1300.0" tabClosingPolicy="UNAVAILABLE" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> <tabs> <Tab fx:id="lecturersTab" closable="false" text="Lecturers"> <content> <BorderPane prefHeight="200.0" prefWidth="200.0"> <center> <TableView prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER"> <columns> <TableColumn prefWidth="75.0" text="C1" /> <TableColumn prefWidth="75.0" text="C2" /> </columns> </TableView> </center> </BorderPane> </content> </Tab> <Tab fx:id="membersTab" closable="false" text="Members"> <content> <BorderPane prefHeight="200.0" prefWidth="200.0"> <center> <fx:include fx:id="memberPage" source="GUImembers.fxml"/> </center> </BorderPane> </content> </Tab> </tabs> </TabPane>
FXML I want to add: 我要添加的FXML:
<?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.control.*?> <?import java.lang.*?> <?import javafx.scene.layout.*?> <BorderPane fx:id="memberPage" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="700.0" prefWidth="1300.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="GUImembersController"> <center> <TableView BorderPane.alignment="CENTER"> <columns> <TableColumn prefWidth="75.0" text="C1" /> <TableColumn prefWidth="75.0" text="C2" /> </columns> </TableView> </center> </BorderPane>
Main: 主要:
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class MainClass extends Application
{
public FXMLLoader loader;
public static void main(String[] args)
{
launch(args);
}
public void start(Stage stage) throws Exception
{
loader = new FXMLLoader();
loader.setLocation(getClass().getResource("FXML/GUImain.fxml"));
loader.setController(new GUImainController());
Parent root = loader.load();
Scene scene = new Scene(root);
stage.setTitle("VIA - Event Management System");
stage.setScene(scene);
stage.show();
}
}
Finally, after long hours of fighting with java fx, I got the sollution, which was quite simple. 最终,经过长时间与java fx的斗争,我得到了解决方案,这很简单。 Thanks to this question : JavaFX Borderpane without left and right children
由于这个问题: JavaFX Borderpane没有左,右子级
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.