javafx在GridPane中调整imageView的大小吗?

时间:2018-09-16 11:45:51

标签: java javafx imageview

我正在使用JavaFx创建菜单屏幕。我想将图像放入按钮中并使其与按钮大小相同。

当前,我正在“网格窗格”中配置菜单。我可以调整按钮中图像的大小吗?

这是我的Java:源代码:

public class AppMain extends Application{

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
         FXMLLoader(getClass().getResource("fxml/loginForm.fxml"));
        Parent root = FXMLLoader.load(getClass().getResource("fxml/main3.fxml"));
        Scene scene = new Scene(root);

        primaryStage.setScene(scene);
        primaryStage.show();
    }

    @Override
    public void stop() throws Exception {
        System.exit(0);
        super.stop();
    }
}

@Override
    public void initialize(URL arg0, ResourceBundle arg1) {
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                bookRentalImg.fitHeightProperty().bind(btnBookRental.heightProperty());
                bookRentalImg.fitWidthProperty().bind(btnBookRental.widthProperty());
                returnBooksImg.fitHeightProperty().bind(btnReturnBooks.widthProperty());
                returnBooksImg.fitWidthProperty().bind(btnReturnBooks.heightProperty());
                bookExtendImg.fitHeightProperty().bind(btnBookExtend.widthProperty());
                bookExtendImg.fitWidthProperty().bind(btnBookExtend.heightProperty());
                wishBookReqImg.fitHeightProperty().bind(btnWishBookReq.maxHeightProperty());
                wishBookReqImg.fitWidthProperty().bind(btnWishBookReq.widthProperty());

            }
        });
    }

这是fxml:

<GridPane maxHeight="1024.0" maxWidth="1280.0" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
  <columnConstraints>
    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
  </columnConstraints>
  <rowConstraints>
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
  </rowConstraints>

                                                                                                                                                                                                                                                                                                                                                                                                                                             

0 个答案:

没有答案