我对 JavaFX(8)、HBox、ComboBox 和 HGrow 有问题。
HGrow 不能与 ComboBox 结合使用。
(信息:使用 TextField (而不是 ComboBox),它按预期工作!)
这是我的 FXML 代码:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox prefHeight="117.0" prefWidth="285.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.test.TestController">
<children>
<HBox prefHeight="105.0" prefWidth="196.0" VBox.vgrow="ALWAYS">
<children>
<ComboBox fx:id="fxCboTest" prefHeight="25.0" prefWidth="62.0" HBox.hgrow="ALWAYS" />
</children>
</HBox>
</children>
</VBox>
此代码将导致:
我也试过下面的代码(没有成功,这段代码什么都不做):
HBox.setHgrow(uiController.fxCboTest, Priority.ALWAYS);
有没有人知道如何制作 ComboBox HGrow?
最佳答案
这是对我自己问题的回答。
经过一些测试,我发现在设置时最大宽度 至 MAX_VALUE ,它的工作原理:
这将导致来自 SceneBuilder 的以下代码/xml:
...
<children>
<ComboBox maxWidth="1.7976931348623157E308" prefWidth="150.0" HBox.hgrow="ALWAYS" />
</children>
...
哪里 1.7976931348623157E308 看起来像 Double.MAX_VALUE。
这也适用于 Hbox 中的多个控件。
在我看来,这不是很因此/始终如一 .
我仍然不明白为什么 HGrow 不适用于 ComboBox。
关于combobox - JavaFX - 如何使 ComboBox hgrow?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29489880/