问题描述
我想做的事:固定柱,液柱(50%),固定柱,液柱(50%)在GridPane中。我有以下FXML:
I want to do: fixed column, liquid column(50%), fixed column, liquid column(50%) in GridPane. And I have the following FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.60-ea" xmlns:fx="http://javafx.com/fxml/1">
<children>
<GridPane layoutX="100.0" layoutY="74.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints>
<ColumnConstraints hgrow="NEVER" maxWidth="-Infinity" minWidth="-Infinity" prefWidth="100.0" />
<ColumnConstraints hgrow="ALWAYS" />
<ColumnConstraints hgrow="NEVER" maxWidth="-Infinity" minWidth="-Infinity" prefWidth="100.0" />
<ColumnConstraints hgrow="ALWAYS" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<ComboBox maxWidth="1.7976931348623157E308" GridPane.columnIndex="3" GridPane.hgrow="ALWAYS" />
<Label text="Label" GridPane.columnIndex="2" />
<TextField GridPane.columnIndex="1" GridPane.hgrow="SOMETIMES" />
<Label text="Label" />
<Label text="Label" GridPane.rowIndex="1" />
<TextField maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text="Label" GridPane.columnIndex="2" GridPane.rowIndex="1" />
<ComboBox maxWidth="1.7976931348623157E308" GridPane.columnIndex="3" GridPane.hgrow="ALWAYS" GridPane.rowIndex="1" />
</children>
</GridPane>
</children>
</AnchorPane>
但是,当我关注组合框时,它们会改变它们的大小。例如,我在SB中开始预览:
现在我按组合框上的箭头:
如您所见,所有布局都已更改。如何解决?
However, when I focus comboboxes they change their size. For example I start preview in SB:And now I press arrow on comboboxes:As you see all layout changed. How to fix it?
推荐答案
您可以使用组合框在网格列上使用min / pref width设置。您将min和pref大小设置为合理的值并保持maxSize相同。
You can use the min/pref width settings on the grid column with the combo boxes. You set the min and pref size to something reasonable and keep maxSize the same.
这可以防止组合框决定它们需要更大的尺寸并仍然保持液柱功能。
This prevents the combo boxes from deciding they need a larger size and still keeps the "liquid column" functionality.
这篇关于JavaFx:组合框最大宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!