【问题标题】:JavaFX - Issue when including another fxml to a border pane center of a main fxmlJavaFX - 将另一个 fxml 包含到主 fxml 的边框窗格中心时出现问题
【发布时间】:2017-12-07 14:59:26
【问题描述】:

我正在尝试在主 fxml、边框窗格中心中包含一个额外的 fxml。当我这样做时,fxml 被包含并显示在中心,但 fxml 不占据主 fxml 窗口的全部宽度和高度。

在 SceneBuilder 中,如果我将 TableView 添加到边框窗格的中心,它会发挥应有的作用。只有当我通过代码包含 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:

<?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>

主要:

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

【问题讨论】:

  • 没有人吗?这让我发疯了...据我所知,无论您在边框布局的中心放置什么,它都应该占据容器的全宽和高度,因为顶部、左侧、右侧没有任何内容和底部。为什么这次没有发生?

标签: java javafx


【解决方案1】:

最后,经过长时间与 java fx 的斗争,我得到了解决方案,这很简单。感谢这个问题:JavaFX Borderpane without left and right children

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-15
    • 1970-01-01
    • 2014-04-09
    • 1970-01-01
    • 1970-01-01
    • 2015-05-29
    • 1970-01-01
    相关资源
    最近更新 更多