【发布时间】:2016-08-07 13:09:08
【问题描述】:
在 FXML (JavaFX) 中按用户调整大小后如何获得新的窗口大小?我搜索了“onResizeWindow”方法,但什么也没找到。
我有一个简单的Pane,我希望它在用户调整窗口大小时自行调整大小。以及如何使用窗格调整工具栏的大小?
这是我的 FXML 代码:
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/null" xmlns:fx="http://javafx.com/fxml/1" fx:controller="testJavaFXML.Controller">
<padding>
<Insets bottom="200.0" left="200.0" right="200.0" top="200.0" />
</padding>
<children>
<ToolBar prefWidth="600.0">
<items>
<Button fx:id="buttonPlay" mnemonicParsing="false" onAction="#handlePlayButtonAction" text="Play" />
<Button fx:id="buttonPause" mnemonicParsing="false" onAction="#handlePauseButtonAction" text="Pause" />
<Button fx:id="buttonStop" mnemonicParsing="false" onAction="#handleStopButtonAction" text="Stop" />
</items>
</ToolBar>
<Label fx:id="labelHelloWorld" layoutX="250.0" layoutY="187.0" text="Hello World!" />
</children>
</Pane>
我找到了如何做到这一点:我必须使用包含Pane 的StackPane,就像这样:
<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/null" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Pane prefHeight="200.0" prefWidth="200.0">
<children>
<ToolBar prefWidth="600.0">
<items>
<Button fx:id="buttonPlay" mnemonicParsing="false" onAction="#handlePlayButtonAction" text="Play" />
<Button fx:id="buttonPause" mnemonicParsing="false" onAction="#handlePauseButtonAction" text="Pause" />
<Button fx:id="buttonStop" mnemonicParsing="false" onAction="#handleStopButtonAction" text="Stop" />
</items>
</ToolBar>
</children>
</Pane>
<Label fx:id="labelHelloWorld" text="Hello World!" />
</children>
</StackPane>
【问题讨论】:
标签: java user-interface javafx fxml window-resize