JavaFx:组合框最大宽度

JavaFx: combobox max width

我想在GridPane中做:fixed column, liquid column(50%), fixed column, liquid column(50%)。我有以下 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 中开始预览: 现在我按下组合框上的箭头: 如您所见,所有布局都已更改。如何解决?

您可以在带有组合框的网格列上使用 min/pref 宽度设置。您将 min 和 pref 大小设置为合理的值并保持 maxSize 相同。

这可以防止组合框决定它们需要更大的尺寸并仍然保持 "liquid column" 功能。