[英]JavaFX resize button in HBox FXML
So Im doing some app layout and I need to put two buttons on bottom of window. 因此,我正在做一些应用程序布局,我需要在窗口底部放置两个按钮。 I want them also to resize whenever I change window size, is it possible to do it in SceneBuilder or modyfing fxml?
我希望每当我更改窗口大小时也要调整它们的大小,是否可以在SceneBuilder或modyfing fxml中进行调整? I cannot find anything that would do it.
我找不到能做到的任何事情。 I know its possible using code to bind widthProperty of parent to child but I want make it without it.
我知道有可能使用代码将父级的widthProperty绑定到子级,但是我希望没有它。
FXML code: FXML代码:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="200.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
<left>
<AnchorPane prefHeight="400.0" prefWidth="170.0" style="-fx-border-color: black; -fx-border-width: 0 2 0 0;" BorderPane.alignment="CENTER">
<children>
<ComboBox layoutY="2.0" prefHeight="25.0" prefWidth="170.0" />
<RadioButton layoutY="27.0" mnemonicParsing="false" text="RadioButton" />
<RadioButton layoutY="51.0" mnemonicParsing="false" text="RadioButton" />
<RadioButton layoutY="74.0" mnemonicParsing="false" text="RadioButton" />
<Label alignment="TOP_CENTER" layoutY="386.0" maxHeight="15.0" prefHeight="15.0" prefWidth="170.0" style="-fx-background-color: violet;" text="Label" AnchorPane.bottomAnchor="0.0" />
</children>
</AnchorPane>
</left>
<center>
<AnchorPane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<children>
<TextField layoutY="2.0" prefHeight="165.0" prefWidth="330.0" promptText="WITAM" text="heh" AnchorPane.bottomAnchor="25.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
<HBox layoutX="14.0" layoutY="147.0" prefHeight="25.0" prefWidth="320.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<children>
<Button maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="25.0" text="Button" />
<Button mnemonicParsing="false" text="Button" />
</children>
</HBox>
</children>
</AnchorPane>
</center>
</BorderPane>
You have to set HBox.hgrow
to ALWAYS
or SOMETIMES
(in the node) that the node can grow with the HBox
. 您必须将
HBox.hgrow
设置为ALWAYS
或SOMETIMES
(在节点中),以便节点可以随HBox
增长。 And you should ensure that the node can grow, for example the Button has a default maxWidth which is the computed size, so change it. 并且您应该确保节点可以增长,例如Button具有默认的maxWidth,它是计算得出的大小,因此请对其进行更改。
This is how it should look like: 它应该是这样的:
<HBox>
<children>
<Button maxWidth="1.7976931348623157E308" HBox.hgrow="ALWAYS" text="Button" />
</children>
</HBox>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.