我之前的问题不太清楚,我只是改写了一下。这是我想要实现的目标。
那么,我该怎么做?谢谢
答案 0 :(得分:0)
ImageViewerController .java
public class ImageViewerController implements Initializable {
private Label label;
@FXML
private ImageView imageView;
@FXML
private TextField txt_Path;
private Image image;
String name;
@Override
public void initialize(URL url, ResourceBundle rb) {
}
@FXML
private void btn_Valide(ActionEvent event) {
loadImage();
}
private void loadImage(){
name = txt_Path.getText();
File file = new File("src/images/"+name);
Image image = new Image(file.toURI().toString());
imageView.setImage(image);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.image.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="521.0" prefWidth="660.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="imageviewer.ImageViewerController">
<center>
<Pane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<children>
<Pane layoutX="24.0" layoutY="248.0" prefHeight="248.0" prefWidth="306.0" style="-fx-background-color: #EBDEF0;">
<children>
<ImageView fx:id="imageView" fitHeight="237.0" fitWidth="297.0" layoutX="7.0" layoutY="8.0" pickOnBounds="true" preserveRatio="true" />
</children>
</Pane>
<TextField fx:id="txt_Path" layoutX="24.0" layoutY="28.0" prefHeight="25.0" prefWidth="510.0" text="avatar.jpg" />
<Button layoutX="549.0" layoutY="28.0" mnemonicParsing="false" onAction="#btn_Valide" prefHeight="25.0" prefWidth="77.0" text="Valide" />
</children>
</Pane>
</center>
</BorderPane>