0
現在、私のJavaFX ZOOプロジェクトに取り組んでいますが、問題があります。 TableViewにすべてのレコードを表示していて、列の1つに削除ボタンが含まれています。それはすべて正常に動作しますが、安全のためだけに、削除ボタンをクリックした後に警告ボックスが表示されます。ボタンをクリックするとJavaFX警告ボックスが表示される
だから私の削除ボタンクラスは次のようになります。
パブリッククラスAlertBox {
public static void display(String title, String message){
Stage window = new Stage();
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle(title);
window.setMinWidth(250);
Label label = new Label();
label.setText(message);
Button deleteButton = new Button("I'm sure, delete!");
VBox layout = new VBox(10);
layout.getChildren().addAll(label,deleteButton);
layout.setAlignment(Pos.CENTER);
Scene scene = new Scene(layout);
window.setScene(scene);
window.showAndWait();
}
}
:private class ButtonCell extends TableCell<Record, Boolean> {
final Button cellButton = new Button("Delete");
ButtonCell(){
cellButton.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent t) {
Animal currentAnimal = (Animal) ButtonCell.this.getTableView().getItems().get(ButtonCell.this.getIndex());
data.remove(currentAnimal);
}
});
}
@Override
protected void updateItem(Boolean t, boolean empty) {
super.updateItem(t, empty);
if(!empty){
setGraphic(cellButton);
}
}
}
はまた、私のAlertBoxクラスは次のようになります
「削除」ボタンをクリックした後、アラートボックスが表示され、許可を求められた後、削除コードの残りの部分が実行されているので、これを作っています。
AlertBoxクラスの代わりにfert:http://code.makery.ch/blog/javafx-dialogs-official/(確認ダイアログ) を追加するとも考えられますが、実装方法はわかりません。
助けがあれば助かります。ありがとう:)
うわー、素晴らしい仕事!ありがとうチャンドラー:) –