【发布时间】:2017-05-23 12:30:02
【问题描述】:
这是场景,我有一个主窗口,我单击一个按钮会打开一个弹出窗口。在这个弹出窗口中,我有一个表格视图,其中显示了一些数据,并且它有一个名为 select 的按钮。从表格视图中选择数据后,当我按下选择按钮时,我希望这个弹出窗口关闭,我从中选择的数据出现在我的主窗口中。
到目前为止,我唯一能做的就是从弹出窗口中提取数据,我希望它也只需单击一下即可关闭
private void venueDisplay(String title, String message) {
Stage window = new Stage();
//Block events to other windows
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle(title);
window.setMinWidth(400);
HBox hBox = new HBox();
hBox.setPadding(new Insets(10,10,10,10));
hBox.setSpacing(10);
hBox.setMaxHeight(20);
hBox.setAlignment(Pos.BOTTOM_CENTER);
hBox.getChildren().add(selectVenueButton);
//Display all the available venues to choose for allocation
VBox layout = new VBox(10);
venueList = new ListView<>();
ObservableList<Venue> observableVenue = FXCollections.observableArrayList(model.getVenues());
venueList.setItems(observableVenue);
layout.getChildren().addAll(venueList, hBox);
//Display window and wait for it to be closed before returning
Scene scene1 = new Scene(layout,300,500);
window.setScene(scene1);
window.showAndWait();
}
public void selectButtonHandler(EventHandler<ActionEvent> handler) {
selectVenueButton.setOnAction(handler);
}
【问题讨论】:
-
您的数据是如何存储的?
-
它存储在.txt文件中。
-
我创建了一个类似的应用程序。我使用 SQLite 来存储数据。我认为你应该使用 SQLite。确保您的 TableView 类有一个 ID 变量,您不必在 TableView 中显示此数据。您还需要一个属性表或数据库。您应该将 id 存储在 selectbuttonaction 和/或 popupclose 的属性表中。在 popup.showandwait() 之后检索该 ID 并对其运行查询。
-
这是一个学校项目,我们只允许使用javafx和txt文件。如果我无法弄清楚一键两次操作,那么我将使用更简单的方法。
-
好吧,您可以将文本字段视为数据库。每个新行都以唯一的 id 开头,后面的数据可能用冒号分隔。这个想法是一样的,它只是想要和数据库一样快。 Ex id:名字:姓氏:生日。这样,当您根据 id 获取行并将其拆分时,返回的数组将为 array[o] = id、array[1] = firstname array[2] = lastname 和 array[3] =birthday。永远都是这样。如果你缺少数据,你会做类似 => id :: lastname :birthday 之类的事情。