import javafx.stage.Stage; import javafx.stage.StageStyle; import javafx.stage.DirectoryChooser; import javafx.fxml.FXML; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.TilePane; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.event.ActionEvent; import javafx.scene.input.KeyEvent; import javafx.scene.input.KeyCode; import javafx.scene.input.MouseEvent; import java.io.File; public class Controller { private DirectoryChooser folderChooser = new DirectoryChooser(); private Image pth = new Image("."); private Image previewPth = new Image("."); private ImageView imgView = new ImageView(pth); private String textAreaPth = ""; private File directory; @FXML // fx:id="dir" private Label dir; // Value injected by FXMLLoader @FXML // fx:id="txtDirPath" private TextField txtDirPath; // Value injected by FXMLLoader @FXML // fx:id="clear" private Button clear; // Value injected by FXMLLoader @FXML // fx:id="tilePane" private TilePane tilePane; // Value injected by FXMLLoader // Handler for TextArea[fx:id="txtDirPath"] onKeyReleased @FXML void onEnter(KeyEvent event) { if (event.getCode().equals(KeyCode.ENTER)) { textAreaPth = txtDirPath.getText(); System.out.println(textAreaPth); newDir(); } else System.out.println("Not calling newDir..."); } // Handler for Button[fx:id="dir"] onAction @FXML void setNewDir(MouseEvent event) { newDir(); } @FXML void clearBttnClick(ActionEvent event) { tilePane.getChildren().clear(); tilePane.getChildren().addAll(dir); } public void newDir() { Stage stage = new Stage(); if (textAreaPth != "") directory = new File(textAreaPth); else directory = folderChooser.showDialog(stage); File[] fileList = directory.listFiles(); int size = fileList.length; tilePane.getChildren().clear(); txtDirPath.setText("" + directory); for (int i=0; i { displayImg(imgViewPoped, title); }); } } public void displayImg(ImageView imgViewPoped, String title) { imgViewPoped.setLayoutX(0); imgViewPoped.setLayoutY(0); Stage popOut = new Stage(); Pane pane = new Pane(); imgViewPoped.fitWidthProperty().bind(pane.widthProperty()); imgViewPoped.fitHeightProperty().bind(pane.heightProperty()); pane.getChildren().addAll(imgViewPoped); Scene scene = new Scene(pane, 1280, 900); popOut.setTitle(title); popOut.initStyle(StageStyle.UNDECORATED); popOut.setScene(scene); popOut.show(); imgViewPoped.setOnMouseClicked(e -> { popOut.close(); }); } @FXML // This method is called by the FXMLLoader when initialization is complete void initialize() { assert clear != null : "fx:id=\"clear\" was not injected: check your FXML file 'window.fxml'."; assert dir != null : "fx:id=\"dir\" was not injected: check your FXML file 'window.fxml'."; assert tilePane != null : "fx:id=\"tilePane\" was not injected: check your FXML file 'window.fxml'."; assert txtDirPath != null : "fx:id=\"txtDirPath\" was not injected: check your FXML file 'window.fxml'."; // Initialize your logic here: all @FXML variables will have been injected } }