2017-06-22 73 views
-1

我想補充的行動TableColumn的兩扣TableColumn中添加兩個按鈕,我已經讀過這How to add button in JavaFX table viewAdd a button to a cells in a TableView (JAVAFX)但他們兩人在setGraphic使用一個按鈕,所以當我嘗試使用:如何TableView中的JavaFX的

actionFld.setCellFactory(param -> new TableCell<Patient, Patient>() { 
    private final JFXButton editButton = new JFXButton("edit"); 
    private final JFXButton deleteButton = new JFXButton("delete"); 

    @Override 
    protected void updateItem(Patient patient, boolean empty) { 
     super.updateItem(patient, empty); 

     if (patient == null) { 
      setGraphic(null); 
      return; 
     } 

     deleteButton.setOnAction(event -> { 
      Patient getPatient = getTableView().getItems().get(getIndex()); 
      System.out.println(getPatient.getNom() + " " + getPatient.getPrenom()); 
     }); 

     editButton.setOnAction(event -> { 
      Patient getPatient = getTableView().getItems().get(getIndex()); 
      System.out.println(getPatient.getNom() + " " + getPatient.getPrenom()); 
     }); 

     setGraphic(deleteButton);//<<<---------------add button 1 
     setGraphic(editButton);//<<------------------add button 2 
    } 
}); 

它告訴我只有一個按鈕:

just one button

我怎樣才能解決這個問題?

回答

1

您可以使用HBox添加您的組件之一,另一個旁邊例如:

HBox pane = new HBox(deleteButton, editButton); 
setGraphic(pane); 

結果:

HBox


如果您有其他的方式,我會爲它而開心!