2017-06-22 72 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


如果您有其他的方式,我会为它而开心!