【发布时间】:2020-06-07 09:24:13
【问题描述】:
我希望调整窗口大小以适应按下按钮时改变大小的 ImageView。 ImageView 包含在 AnchorPane 中。我似乎找不到任何解释如何执行此操作的资源,也无法在 SceneBuilder 中找到任何内容。谢谢!
<AnchorPane prefHeight="400" prefWidth="600" style="-fx-background-color: #282828;" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller">
<children>
<HBox maxHeight="-Infinity" maxWidth="-Infinity" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<VBox prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: #535353;">
<children>
<Pane prefHeight="50.0" prefWidth="100.0" />
<Button fx:id="topButton" mnemonicParsing="false" onAction="#handleTopButton" prefHeight="25.0" prefWidth="100.0" text="Top" />
<Button fx:id="sideButton" mnemonicParsing="false" onAction="#handleSideButton" prefHeight="25.0" prefWidth="100.0" text="Side" />
<Button fx:id="frontButton" mnemonicParsing="false" onAction="#handleFrontButton" prefHeight="25.0" prefWidth="100.0" text="Front" />
<Pane prefHeight="50.0" prefWidth="100.0" />
<Label fx:id="scaleLabel" prefHeight="17.0" prefWidth="103.0" text="Scale" textAlignment="CENTER" textFill="WHITE" />
<Slider fx:id="scale" max="3.0" min="1.0" />
<Label fx:id="sliceLabel" text="Slice" textAlignment="CENTER" textFill="WHITE" />
<Slider fx:id="slice" disable="true" />
<Pane prefHeight="50.0" prefWidth="100.0" />
<Button fx:id="mipButton" disable="true" mnemonicParsing="false" onAction="#handleMipButton" prefHeight="25.0" prefWidth="100.0" text="MIP" />
<Button mnemonicParsing="false" prefHeight="25.0" prefWidth="100.0" text="Histogram" />
<Button fx:id="exitButton" mnemonicParsing="false" onAction="#handleExitButton" prefHeight="25.0" prefWidth="100.0" text="Exit" />
</children>
</VBox>
<ImageView fx:id="imageView"/>
</children>
</HBox>
</children>
【问题讨论】:
-
图片大于用户屏幕怎么办?
-
@Slaw 我想在这种情况下,预期的效果是窗口不能像现在那样容纳图像视图
-
我看不到您为
ImageView设置图像的位置。可以给我看看吗? -
@Abra ImageView 在我发布的 fxml 中有一个 fx:id,当按下按钮时,我在这个 imageView 上使用 setImage(someWritableImage)。
-
您或许可以使用
Window#sizeToScene()。可能需要额外的工作来确保窗口不会超出屏幕的大小。
标签: java user-interface javafx fxml