2017-01-22 87 views
-1

我安排我的javafx布局时遇到了一些麻烦。我使用BorderPane。顶部和左侧区域用于静态视图(页面)。我把MenuBar放在顶部,一些按钮放在左边,就像图中一样。而且,当我点击一个按钮时,内容将在中心打开。每个按钮都有不同的内容和布局。 “Money Box”按钮将为其内容提供TabPane,并使用SceneBuilder创建它。 “咖啡厅”按钮将具有Table的内容,并且我已经使用SceneBuilder创建了它。什么策略,或者我需要做些什么来解决我的问题。在JavaFX上制作主页面(屏幕)

[IMG] http://i.imgur.com/fG6a0kg.png[/img]

回答

0

我不是100%确定究竟你正在寻找,并根据您的描述有很多方法来完成你所需要的。我有类似的行为,我们对每个选定的布局使用不同的FXML,并加载这些布局并将其从场景中移除。

private void openMiddleNode(String view) {} 
    try { 
     FXMLLoader loader = new FXMLLoader(); 
     Parent node = loader.load(getClass().getClassLoader().getResource(view).openStream()); 
     //If your middle section has it's own controller (likely an instance variable, if it needs to respond to events from the parent controller) 
     MyController controller = loader.getController(); 
     controller.anyCustomSetup(); 

     //Assumes that this middlePane is defined in the FXML and initialized above 
     middlePane.getChildren().setAll(node); 
    } catch (IOException ie){ 
     if(logger.isErrorEnabled()){ 
      logger.error("An exception has been thrown: " + ie); 
     } 
    } 
} 
+0

谢谢你的回答。我的问题是如何在borderpane左侧的按钮上放置一个动作,以在borderpane的CENTER中显示一个fxml文件设计。我正在使用borderpane作为根窗格。 – rizal

+0

然后使用borderPane.setCenter(节点)而不是middlePane.getChildren()。setAll()假设borderPane是窗格的名称。从您的点击处理程序调用此方法。 –