我有一个 View ,其中 SplitPane
中有两个垂直方向的 TitledPane
。我希望当我折叠其中一个时,将另一个的大小调整为场景的高度。这是我的 .fxml
文件的代码:
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TableColumn?>
<BorderPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:id="pane"
fx:controller="stackoverflow.three.Controller">
<center>
<SplitPane fx:id="split" orientation="VERTICAL">
<TitledPane fx:id="first" text="First">
<TableView>
<columns>
<TableColumn text="Test"/>
</columns>
</TableView>
</TitledPane>
<TitledPane fx:id="second" text="Second">
<TableView>
<columns>
<TableColumn text="Test"/>
</columns>
</TableView>
</TitledPane>
</SplitPane>
</center>
</BorderPane>
正如您所看到的,如果我折叠第一个 View , View 底部会有一个间隙,但我不想要这个间隙。
我尝试将 maxHeight
设置为无限,但随后自动移动到第一个位置不起作用...
知道我能做什么吗?
最佳答案
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TableColumn?>
<BorderPane fx:id="pane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="stackoverflow.three.Controller">
<center>
<VBox prefHeight="800.0">
<children>
<TitledPane fx:id="first" text="First">
<content>
<TableView prefHeight="2000.0">
<columns>
<TableColumn text="Test" />
</columns>
</TableView>
</content>
</TitledPane>
<TitledPane fx:id="second" text="Second">
<content>
<TableView prefHeight="2000.0">
<columns>
<TableColumn text="Test" />
</columns>
</TableView>
</content>
</TitledPane>
</children>
</VBox>
</center>
</BorderPane>
关于JavaFx:自动调整 TitledPane 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47413305/