2016-07-29 23 views
0

Ich arbeite derzeit an javafx und ich habe ein ernstes Problem. Ich kann keine Möglichkeit finden, den Index der Zeile einer Schaltfläche, die ich dynamisch erstellt habe, in einer Tabellenansicht abzurufen.Wie Sie die Zeile einer dynamisch erstellten Schaltfläche einer Tabellenansicht auf javafx kennen

Wenn mir jemand helfen könnte, wäre das sehr hilfreich.

this.clmColumn.setCellFactory((TableColumn<?, ?> column) -> { 
      return new TableCell<?, ?>() { 
       @Override 
       protected void updateItem(? item, boolean empty) { 

        super.updateItem(item, empty); 
        if (!empty) { 
         final HBox hbox = new HBox(5); 
         final VBox vbox = new VBox(5); 
         Label label = new Label(item.toString()); 
         final Button btnMais = new Button("+"); 
         btnMais.setMinSize(25, 25); 
         final TableCell<?, ?> c = this; 
         btnMais.setOnAction(new EventHandler<ActionEvent>() { 
          @Override 
          public void handle(ActionEvent event) { 
           // At this point i want to select the current ROW of the button that i pressed on the tableview. 

          } 
         }); 
         final Button btnMenos = new Button("-"); 
         btnMenos.setMinSize(25, 25); 
         btnMenos.setOnAction(new EventHandler<ActionEvent>() { 
          @Override 
          public void handle(ActionEvent event) { 
           if (getItem() > 1) { 
            // At this point i want to select the current ROW of the button that i pressed on the tableview. 

           } 
          } 
         }); 
         final Button btnRemover = new Button("Remover"); 
         btnRemover.setFont(new Font(8)); 
         btnRemover.setOnAction(new EventHandler<ActionEvent>() { 
          @Override 
          public void handle(ActionEvent event) { 
           // At this point i want to select the current ROW of the button that i pressed on the tableview. 

          } 
         }); 
         vbox.getChildren().add(hbox); 
         vbox.getChildren().add(btnRemover); 
         hbox.getChildren().add(btnMais); 
         hbox.getChildren().add(label); 
         hbox.getChildren().add(btnMenos); 
         hbox.setAlignment(Pos.CENTER); 
         vbox.setAlignment(Pos.CENTER); 
         setGraphic(vbox); 
        } else { 
         setGraphic(null); 
        } 

       } 
      }; 
     }); 

Antwort

0

Im handle() Methode können Sie

Object row = getTableView.getItems().get(getIndex()); 

tun Sie Object mit einem spezielleren Art ersetzen können, wenn Sie speziellere Typen im ganzen in den Typ-Parameter verwenden.

+0

Vielen Dank! Das ist die richtige Antwort! – helpplz