-1

I wasn't very clear on my previous question, and I just rephrased it. Here is what I trying to achieve.

  • I want to define a path to a folder;
  • on the FROM ->TextField, Customer will enter the image name which already exist in the folder;
  • Click on a button and the file name will be added to the path and populate it to the imageView without manually browsing to the folder.

So, how can I do that? Thanks

DavidS
  • 5,022
  • 2
  • 28
  • 55
livreson ltc
  • 733
  • 8
  • 22
  • Possible duplicate of [How do I restrict JFileChooser to a directory?](https://stackoverflow.com/questions/32529/how-do-i-restrict-jfilechooser-to-a-directory) – sorifiend Oct 02 '18 at 03:10
  • Take a look at the answer from Allain and the modifications from mlh on in the above link. Or if you prefer you can just make your own file chooser that just shows a list of items from the directory in a jList. – sorifiend Oct 02 '18 at 03:11
  • @sorifiend, I wasn't clear on my question. I just rephrased it. Thanks – livreson ltc Oct 02 '18 at 17:41

1 Answers1

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>
livreson ltc
  • 733
  • 8
  • 22