Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
调整窗口大小以适应ImageView(JavaFX)_Java_User Interface_Javafx_Fxml - Fatal编程技术网

调整窗口大小以适应ImageView(JavaFX)

调整窗口大小以适应ImageView(JavaFX),java,user-interface,javafx,fxml,Java,User Interface,Javafx,Fxml,我希望调整窗口的大小,使其适合在按下按钮时改变大小的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

我希望调整窗口的大小,使其适合在按下按钮时改变大小的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>
使用符合其所包含节点的首选大小的容器,例如。 按问题中所述单击按钮后更改图像时,调用方法调整应用程序窗口的大小。 下面是上述内容的一个非常简单的实现。 注意:在下面的代码中,用图像构造函数中图像的实际url替换url

导入javafx.application.application; 导入javafx.geometry.Pos; 导入javafx.scene.scene; 导入javafx.scene.control.Button; 导入javafx.scene.image.image; 导入javafx.scene.image.ImageView; 导入javafx.scene.layout.BorderPane; 导入javafx.scene.layout.HBox; 导入javafx.stage.stage; 公共类ImgVwTst扩展了应用程序{ @凌驾 public void startStage primaryStage引发异常{ BorderPane根=新的BorderPane; 图像img=新的图像URL; ImageView imgVw=新ImageViewimg; root.setCenterimgVw; HBox HBox=新的HBox; hBox.setAlignmentPos.CENTER; Button nextImageButton=新按钮next; nextImageButton.setOnActione->{Image img2=新图像URL; imgVw.setImageimg2; primaryStage.sizeToScene;}; hBox.getChildren.addnextImageButton; 根;立根; 场景=新场景; 初生阶段;初生阶段; 初级舞台表演; } 公共静态无效字符串[]args{ 发射艇; } }
如果图像比用户的屏幕大,该怎么办?@Slaw我想在这种情况下,预期的效果是窗口不能容纳imageview,因为情况就是这样。我看不到您在哪里为imageview设置了图像。你能给我看一下吗?@Abra在我发布的fxml中imageView有一个fx:id,当按下按钮时,我在这个imageView上使用setImagesomeWritableImage。你可能可以使用。可能需要额外的工作,以确保窗口不会超出屏幕大小。