JavaFX - TabPane / Tab如何添加填充选项卡大小的内容? [英] JavaFX - TabPane/Tab How to add content which fills the tab in size?

查看:263
本文介绍了JavaFX - TabPane / Tab如何添加填充选项卡大小的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在玩JavaFX,我有一个小问题,我无法解决。

我想在现有的TabPane中添加一个新的Tab(从FXML)。


I am playing with JavaFX and i have a small problem, which i cannot solve.
I want to add a new Tab (from FXML) to a existing TabPane.

这是我的代码:

try
{
   URL location = WPClientController.class.getResource("WPClient.fxml"); 
   FXMLLoader fxmlLoader = new FXMLLoader();
   fxmlLoader.setLocation(location);
   fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());
   Node node = (Node) fxmlLoader.load(location.openStream());

   Tab newTab = new Tab("engel", node);
   fxTabWP.getTabs().add(newTab);
}
catch (Exception exception)
{
  //no real error handling...just print the stacktrace... 
  exception.printStackTrace();
}

此代码将导致:

代码可以工作,但是(如截图所示)添加的节点(这里的SplitPane)使用它的首选大小(在TabPage上,这对我来说是错误的。)
添加的SplitPane的大小应该有与它的父容器大小相同。 (当父容器增长或缩小时它应该增长和缩小)(如Swing中的BorderLayout)

The code works, but (as seen on the screenshot) the added node (a SplitPane here) uses it's preferred size (on TabPage, which is wrong for me).
The size of the added SplitPane should have the same size as it's parent container. (and it should grow and shrink, when the parent container grows or shrinks) (like BorderLayout in Swing)

编辑(这里是TAB的[现在是正确的]内容FXML):

EDIT (here is [now the correct] content of the TAB FXML):

 <?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.test.ui.fx.client.ClientController">
 <children>
  <HBox prefHeight="100.0" prefWidth="200.0" VBox.vgrow="ALWAYS">
     <children>
        <SplitPane dividerPositions="0.29797979797979796" prefHeight="160.0" prefWidth="200.0" HBox.hgrow="ALWAYS">
          <items>
              <HBox prefHeight="100.0" prefWidth="200.0">
                 <children>
                    <TreeView fx:id="fxTreeView" prefHeight="200.0" prefWidth="200.0" HBox.hgrow="ALWAYS" />
                 </children>
              </HBox>
              <HBox fx:id="fxTreeNodeContentBox" prefHeight="100.0" prefWidth="200.0" />
          </items>
        </SplitPane>
     </children>
    </HBox>
 </children>
</VBox>

我的问题:什么是待办事项,因此SplitPane的尺寸将动态适应它的父容器大小?

My question: What is todo, so the SplitPane's size will dynamically fit it's parent container size?

推荐答案

你的FXML文件有一个根元素

Your FXML file has a root element with

<VBox maxHeight="-Infinity" maxWidth="-Infinity" ... >

maxHeight maxWidth 属性阻止它超出其首选大小。 (此外,由于某种原因,其子元素的首选大小设置为固定值。)如果删除这些属性,它将允许根元素根据需要增长。

The maxHeight and maxWidth attributes are preventing it from growing beyond its preferred size. (In addition, the preferred sizes of its child elements are, for some reason, set to fixed values.) If you remove these attributes it will allow the root element to grow as needed.

这篇关于JavaFX - TabPane / Tab如何添加填充选项卡大小的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆