Javafx 最大化阶段时调整TableView的大小
我试图在一个锚面板中调整两个表的大小,当舞台被最大化以与默认舞台大小具有相同的比例时 现在我知道了: 但当最大化时,它们之间有很大的空间: 我一直在搜索,我找到了类似问题的答案,如“在网格面板中包裹”,但即使如此,我也无法做到: 有人知道这里少了什么吗 代码fxml:Javafx 最大化阶段时调整TableView的大小,javafx,tableview,javafx-8,fxml,autoresize,Javafx,Tableview,Javafx 8,Fxml,Autoresize,我试图在一个锚面板中调整两个表的大小,当舞台被最大化以与默认舞台大小具有相同的比例时 现在我知道了: 但当最大化时,它们之间有很大的空间: 我一直在搜索,我找到了类似问题的答案,如“在网格面板中包裹”,但即使如此,我也无法做到: 有人知道这里少了什么吗 代码fxml: <AnchorPane styleClass="backgroundColor" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/
<AnchorPane styleClass="backgroundColor" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="solverassistant.FXMLCompareController">
<children>
<AnchorPane prefHeight="270" prefWidth="190.0" styleClass="filterPane" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="40.0">
<children>
<Label id="filterLabel" fx:id="filterLabel" alignment="CENTER" prefHeight="17.0" prefWidth="150.0" text="Filter" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="10.0" />
<TextField id="filterTextField" fx:id="filterTextField" alignment="CENTER" layoutY="20.0" prefWidth="150.0" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="30.0" />
<Label id="filterByLabel" fx:id="filterByLabel" alignment="CENTER" prefHeight="17.0" prefWidth="150.0" text="Filter by:" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="70.0" />
<CheckBox id="solverCheckBox" fx:id="solverCheckBox" layoutY="90.0" selected="true" text="Solver" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="100.0" />
<CheckBox id="benchmarkCheckBox" fx:id="benchmarkCheckBox" layoutY="110.0" selected="true" text="Benchmark" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="120.0" />
<CheckBox id="typeCheckBox" fx:id="typeCheckBox" layoutY="130.0" selected="true" text="Solver type" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="140.0" />
<CheckBox id="timeOutCheckBox" fx:id="timeOutCheckBox" layoutY="150.0" selected="true" text="Time out" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="160.0" />
<CheckBox id="memoryCheckBox" fx:id="memoryCheckBox" layoutY="170.0" selected="true" text="Memory" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="180.0" />
<CheckBox id="coresCheckBox" fx:id="coresCheckBox" layoutY="190.0" selected="true" text="Number of cores" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="200.0" />
<CheckBox id="wholeWordCheckBox" fx:id="wholeWordCheckBox" layoutY="190.0" selected="false" text="Whole word" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="220.0" />
</children>
</AnchorPane>
<Button id="reloadButton" fx:id="reloadButton" onAction="#resetAndReloadSolvers" prefHeight="25.0" prefWidth="190.0" styleClass="button-defaultButton" text="Reset and reload data" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="320.0" />
<Button id="compareButton" fx:id="compareButton" disable="true" prefHeight="25.0" prefWidth="150.0" styleClass="button-defaultButton" text="Compare" AnchorPane.bottomAnchor="50.0" AnchorPane.leftAnchor="40.0" />
<TableView id="allSolversTable" fx:id="allSolversTable" minHeight="-Infinity" prefHeight="175.0" prefWidth="922.0" AnchorPane.leftAnchor="245.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="40.0">
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
<columns>
<TableColumn fx:id="colAllSelect" prefWidth="25.0" />
<TableColumn fx:id="colAllSolver" prefWidth="75.0" text="Solver" />
<TableColumn fx:id="colAllBenchmark" prefWidth="75.0" text="Benchmark" />
<TableColumn fx:id="colAllSolverType" prefWidth="75.0" text="Solver type" />
<TableColumn fx:id="colAllTimeOut" prefWidth="75.0" text="Time out" />
<TableColumn fx:id="colAllMemory" prefWidth="75.0" text="Memory" />
<TableColumn fx:id="colAllNumberOfCores" prefWidth="75.0" text="Number of cores" />
</columns>
</TableView>
<TableView id="selectedSolversTable" fx:id="selectedSolversTable" minHeight="-Infinity" prefHeight="175.0" prefWidth="922.0" AnchorPane.bottomAnchor="50.0" AnchorPane.leftAnchor="245.0" AnchorPane.rightAnchor="0.0">
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
<columns>
<TableColumn fx:id="colSelectedSolver" prefWidth="75.0" text="Solver" />
<TableColumn fx:id="colSelectedBenchmark" prefWidth="75.0" text="Benchmark" />
<TableColumn fx:id="colSelectedSolverType" prefWidth="75.0" text="Solver type" />
<TableColumn fx:id="colSelectedTimeOut" prefWidth="75.0" text="Time out" />
<TableColumn fx:id="colSelectedMemory" prefWidth="75.0" text="Memory" />
<TableColumn fx:id="colSelectedNumberOfCores" prefWidth="75.0" text="Number of cores" />
</columns>
</TableView>
</children>
</AnchorPane>
所有项目:github.com/danielcasanovas/SolverAssistant您可以做的一件简单的事情就是将两个表都包装在
VBox
中,让第一个表的垂直增长优先级设置为始终,并在所有最小/首选/最大大小字段中设置使用计算大小
。第二个表可以保持原样(因此只调整第一个表的大小)
这是FXML文件的受影响部分:
<VBox spacing="40.0" AnchorPane.bottomAnchor="40.0" AnchorPane.leftAnchor="245.0" AnchorPane.rightAnchor="40.0" AnchorPane.topAnchor="40.0">
<children>
<TableView id="allSolversTable" fx:id="allSolversTable" VBox.vgrow="ALWAYS">
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
<columns>
<TableColumn fx:id="colAllSelect" prefWidth="25.0" />
<TableColumn fx:id="colAllSolver" prefWidth="75.0" text="Solver" />
<TableColumn fx:id="colAllBenchmark" prefWidth="75.0" text="Benchmark" />
<TableColumn fx:id="colAllSolverType" prefWidth="75.0" text="Solver type" />
<TableColumn fx:id="colAllTimeOut" prefWidth="75.0" text="Time out" />
<TableColumn fx:id="colAllMemory" prefWidth="75.0" text="Memory" />
<TableColumn fx:id="colAllNumberOfCores" prefWidth="75.0" text="Number of cores" />
</columns>
</TableView>
<TableView id="selectedSolversTable" fx:id="selectedSolversTable" prefHeight="175.0">
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
<columns>
<TableColumn fx:id="colSelectedSolver" prefWidth="75.0" text="Solver" />
<TableColumn fx:id="colSelectedBenchmark" prefWidth="75.0" text="Benchmark" />
<TableColumn fx:id="colSelectedSolverType" prefWidth="75.0" text="Solver type" />
<TableColumn fx:id="colSelectedTimeOut" prefWidth="75.0" text="Time out" />
<TableColumn fx:id="colSelectedMemory" prefWidth="75.0" text="Memory" />
<TableColumn fx:id="colSelectedNumberOfCores" prefWidth="75.0" text="Number of cores" />
</columns>
</TableView>
</children>
</VBox>
在主fxml文件中没有进一步更改的情况下,在应用程序进行任何调整后,表应该正确调整大小。对于布局问题,通常VBox
和HBox
都会派上用场。到目前为止,你的项目看起来真的很好。我会做的,非常感谢。一切都可能长大吗?就像HBox中的标签一样?通常你有一些固定大小的控件和一些可调整大小的控件,但是你可以将某些容器的所有项目设置为始终增长,并且它们将以相同的比例调整大小。是的,我可以看到它,因为例如:不要使标签增长,正如你说的,我必须把它放在另一个容器中,对吗?标签不会增长(意味着文本字体不会放大/缩小,其固定宽度也不会改变),如果你将宽度设置为使用计算大小,则该宽度是显示的字符串所需的最小宽度,并且也不会增长。因此,将每个标签包装在一个HBox
中,并将此框设置为始终增长,一旦将所有这些框包装在outterHBox
中,就可以了。