我在 JavaFX 中有这个简单的对话框:
Stage dialogStage = new Stage();
dialogStage.initModality(Modality.WINDOW_MODAL);
dialogStage.setScene(new Scene(VBoxBuilder.create()
.children(new Text(text), new Button("Close")).alignment(Pos.CENTER).padding(new Insets(5)).build(), xSize, ySize, backgroundColor));
dialogStage.show();
我想在单击Close
按钮时关闭对话框,因此我以这种方式修改了代码:
Stage dialogStage = new Stage();
dialogStage.initModality(Modality.WINDOW_MODAL);
dialogStage.setScene(new Scene(VBoxBuilder.create()
.children(new Text(text), new Button("Close").setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
aboutDialog();
}
})).alignment(Pos.CENTER).padding(new Insets(5)).build(), xSize, ySize, backgroundColor));
dialogStage.show();
但我在 Netbeans 中收到此错误消息:'void' type not allowed here
你能告诉他们使用Close
按钮关闭对话框的正确方法是什么吗?