【问题标题】:JavaFX resize button in HBox FXMLHBox FXML中的JavaFX调整大小按钮
【发布时间】:2017-11-25 13:09:59
【问题描述】:

所以我做了一些应用布局,我需要在窗口底部放置两个按钮。我希望它们在我更改窗口大小时也调整大小,是否可以在 SceneBuilder 或 modyfing fxml 中进行调整?我找不到任何可以做到的事情。我知道它可以使用代码将父级的 widthProperty 绑定到子级,但我希望没有它。

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>

【问题讨论】:

    标签: java javafx scenebuilder


    【解决方案1】:

    您必须将HBox.hgrow 设置为ALWAYSSOMETIMES(在节点中),这样节点才能随着HBox 增长。并且你应该确保节点可以增长,例如 Button 有一个默认的 maxWidth 是计算的大小,所以改变它。

    它应该是这样的:

    <HBox>
        <children>
            <Button maxWidth="1.7976931348623157E308" HBox.hgrow="ALWAYS" text="Button" />
        </children>
    </HBox>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-25
      • 2014-12-16
      • 2018-10-15
      • 2018-05-16
      • 1970-01-01
      • 2016-08-07
      相关资源
      最近更新 更多