javafxのテーブルビューで2つのボタンを1つの列に実装しようとしています。私は1つの列に1つのボタンを実装できますが、1つの列に2つのボタンを追加することはできません。 私は 2つのボタンを1つの列に追加してクリック行の値を取得するjavafx
Add a button to a cells in a TableView (JAVAFX)
How to add two buttons in a TableColumn of TableView JavaFX
私は上記のリンクでアイデアを使用してい
How to add button in JavaFX table view
このリンクからいくつかのアイデアを得ました。しかし、コードは私のために働いていません。TableColumn<Student, String> firstCol = new TableColumn<Student, String>("ID");
TableColumn<Student, String> secondCol = new TableColumn<Student, String>("Name");
TableColumn<Student, String> thirdCol = new TableColumn<Student, String>("Quiz Mark");
TableColumn<Student, String> forthCol = new TableColumn<Student, String>("A1");
TableColumn<Student, String> fifthCol = new TableColumn<Student, String>("A2");
TableColumn<Student, String> sixthCol = new TableColumn<Student, String>("A3");
TableColumn<Student, String> sevenCol = new TableColumn<Student, String>("Exam");
TableColumn<Student, String> eightCol = new TableColumn<Student, String>("Result");
TableColumn<Student, String> nineCol = new TableColumn<Student, String>("Grade");
TableColumn<Student, Student> tenthCol = new TableColumn<Student, Student>("Action");
firstCol.setCellValueFactory(new PropertyValueFactory<>("Id"));
secondCol.setCellValueFactory(new PropertyValueFactory<>("Name"));
thirdCol.setCellValueFactory(new PropertyValueFactory<>("QuizMark"));
forthCol.setCellValueFactory(new PropertyValueFactory<>("Assingment1Mark"));
fifthCol.setCellValueFactory(new PropertyValueFactory<>("Assingment2Mark"));
sixthCol.setCellValueFactory(new PropertyValueFactory<>("Assingment3Mark"));
sevenCol.setCellValueFactory(new PropertyValueFactory<>("ExamMark"));
eightCol.setCellValueFactory(new PropertyValueFactory<>("Result"));
nineCol.setCellValueFactory(new PropertyValueFactory<>("Grade"));
tenthCol.setCellFactory(param -> new TableCell<Student, Student>() {
private final Button editButton = new Button("edit");
private final Button deleteButton = new Button("delete");
HBox pane = new HBox(deleteButton, editButton);
@Override
protected void updateItem(Student patient, boolean empty) {
super.updateItem(patient, empty);
if (patient == null) {
setGraphic(null);
return;
}
deleteButton.setOnAction(event -> {
Student getPatient = getTableView().getItems().get(getIndex());
System.out.println(getPatient.getId() + " " + getPatient.getName());
});
editButton.setOnAction(event -> {
Student getPatient = getTableView().getItems().get(getIndex());
});
pane.getChildren().addAll(deleteButton,editButton);
setGraphic(pane);
}
});
で、アクション列のボタンが表示されていません。どこで私は間違っているのですか?誰でも私に知らせてください。 tenthColumn
のセルのcellValueFactory
項目を欠く