我无法真正理解JavaFX中这种伸缩是如何工作的。我为HBox和TextField都设置了无穷大宽度,所以如果我们调整帧大小,TextField应该更大。请帮助我,我在这里错过了什么。谢谢。为什么我的文本框不能调整大小?
<GridPane fx:id="first" hgap="5" vgap="5" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" >
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" percentWidth="100.0" />
</columnConstraints>
<VBox.margin>
<Insets left="10.0" top="15"/>
</VBox.margin>
<HBox GridPane.columnIndex="0" GridPane.rowIndex="0" prefWidth="Infinity" maxWidth="Infinity">
<fx:define>
<ToggleGroup fx:id="myToggleGroup"/>
</fx:define>
<children>
<RadioButton text="System" toggleGroup="$myToggleGroup">
</RadioButton>
<RadioButton text="Document" toggleGroup="$myToggleGroup">
<HBox.margin>
<Insets left="200.0"/>
</HBox.margin>
</RadioButton>
</children>
</HBox>
<HBox GridPane.rowIndex="1" GridPane.columnIndex="0" >
<Label text="Name:" minWidth="50">
</Label>
<TextField maxWidth="Infinity" minWidth="450" prefWidth="Infinity">
<HBox.margin>
<Insets left="20.0"/>
</HBox.margin>
</TextField>
</HBox>
参见如果HTTP://计算器。 com/questions/35438104/javafx-alignment-of-label-in-gridpane(这是不同的,但对网格窗格中布局的工作原理有完整的解释)有帮助。 –
另外我只允许在这个项目中使用fxml。 – Joey
无关紧要,该问题中的所有内容都可以通过FXML完成。 (虽然,“*只允许使用FXML”???你只能使用FXML编写应用程序,你需要在控制器中使用Java。) –