JavaFx:组合框最大宽度

标签 java javafx

我想做:GridPane中的固定列、液柱(50%)、固定列、液柱(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 中开始预览: enter image description here 现在我按组合框上的箭头: enter image description here 正如您所看到的,所有布局都发生了变化。如何解决?

最佳答案

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

这可以防止组合框决定它们需要更大的尺寸,并且仍然保留“液柱”功能。

关于JavaFx:组合框最大宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30729958/

相关文章:

css - javafx:建立你自己的矩形

JavaFX:我应该使用具有多个 ImageView 的静态图像吗

java - 三元字符串到 Node 类

java - 从编辑文本检索地名到字符串时,来自地理编码器类的 NullPointerException

java - 如何从 Java 代码启动 Apache Storm UI?

java - ListProperty<T> 与 ObjectProperty<ObservableList<T>>

java - 矩形大小绑定(bind)到场景大小 - JavaFX

java - 如何将javaFX中使用filechooser加载的文件名插入到表中?

java - 从 tomcat 6 升级到 tomcat7 出现错误 Abstract Method Error

java - 累积另一个列表中列表的计数