我将再尝试一次...我是Scenebuilder的新手,我正试图为我的项目制作一个照相馆!我已经添加了我想要的东西,那就是一个带有从FileChooser中选择的图像的ImageView。但是现在我想获得一条建议,关于如何保存该图像并在每次按下addPhoto按钮时创建一个新的建议,而不是覆盖ImageView中已经存在的那个。这是我的addPhoto按钮的代码:
@FXML
public void initialize(actionEvent e) throws Exception{
addPhotos.setOnaction(event -> {
FileChooser chooser = new FileChooser();
File file = chooser.showOpenDialog(null);
pic = new Image(file.toURI().toString());
if(pic != null) {
ImageView imgView = new ImageView(pic);
}
imgView.setImage(pic);
});
FXML代码:
<BorderPane prefHeight="737.0" prefWidth="934.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="legioDesk.GalleryController">
<top>
<Button fx:id="addPhotos" mnemonicParsing="false" onaction="#initialize" text="addPhotos" BorderPane.alignment="CENTER" />
</top>
<center>
<TilePane fx:id="tp" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<children>
<ImageView fx:id="imgView" fitHeight="306.0" fitWidth="378.0" pickOnBounds="true" preserveRatio="true" />
</children>
</TilePane>
</center>
</BorderPane>