Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.21 KB | None | 0 0
  1. // u glavnom kontroleru nađi funkciju initialize, i unutar nje bi trebalo da imaš ovakav neki kod
  2.  
  3. lista.setOnMouseClicked(new EventHandler<MouseEvent>() {
  4.             @Override
  5.             public void handle(MouseEvent event) {
  6.                 //System.out.println("clicked on " + lista.getSelectionModel().getSelectedItem());
  7.                 Parent root;
  8.                 try {
  9.                     root = FXMLLoader.load(getClass().getResource("Forma.fxml"));
  10.                     Stage stage = new Stage();
  11.                     stage.setTitle("Slanje datoteke ");
  12.                     stage.setScene(new Scene(root, 400, 150));
  13.                     stage.show();
  14.                     // Ukoliko želite otvoriti u istom prozoru, otkomentarišite kod ispod
  15.                     // ((Node)(event.getSource())).getScene().getWindow().hide();
  16.                 }
  17.                 catch (IOException e) {
  18.                     // handle grešku
  19.                 }
  20.             }
  21.         });
  22.  
  23. // umjesto toga stavi ovo
  24.  
  25. lista.setOnMouseClicked(new EventHandler<MouseEvent>() {
  26.             @Override
  27.             public void handle(MouseEvent event) {
  28.                 //Prevencija za klik na praznu listu, ili prazan red, bez da je išta selektovano
  29.                 if (!lista.getSelectionModel().isEmpty()) {
  30.                     Parent root;
  31.                     try {
  32.                         root = FXMLLoader.load(getClass().getResource("Forma.fxml"));
  33.                         Stage stage = new Stage();
  34.                         stage.setTitle("Slanje datoteke ");
  35.                         stage.setScene(new Scene(root, 400, 150));
  36.                         stage.show();
  37.                         // Ukoliko želite otvoriti u istom prozoru, otkomentarišite kod ispod
  38.                         // ((Node)(event.getSource())).getScene().getWindow().hide();
  39.                     }
  40.                     catch (IOException e) {
  41.                         // handle grešku
  42.                     }
  43.                 }
  44.             }
  45.         });
  46.  
  47. // dakle ključan je ovaj uslov  if (!lista.getSelectionModel().isEmpty()) koji provjerava da li je išta odabrano, tako da više ne otvara prozor za slanje ukoliko nije ništa odabrano ili je prazna ona lista
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement