如何将 TableView1 项添加到 TableView2?
How Can I Add TableView1 items to TableView2?
我正在寻找的重点是获取 tableview1 项目并通过选择 tableview1 行并按加号按钮将其复制到 tableview2 ...
如图所示...
我什么都试过了,但我得到的输出是这样的:
我的代码是:
confirmbutton2.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
itemname2 = tableView1.getSelectionModel().selectedItemProperty().get().toString() ;
tableView1.getSelectionModel().selectedIndexProperty().addListener((num) -> {
itemprice2 = tableView1.getSelectionModel().selectedIndexProperty().get();
itemcount2 = tableView1.getSelectionModel().selectedIndexProperty().get();
});
tableview2.getItems().AddAll(new PersonTransfer(itemname2 , itemprice2 , itemcount2)) ;
检查 TableView1 的第一个选定项目,然后添加到 TableView2。请在 .
中查看完整的 TableView 示例代码
public void onAddItem() {
// check the table's selected item and get selected item
if (table.getSelectionModel().getSelectedItem() != null) {
Person selectedPerson = table.getSelectionModel().getSelectedItem();
// add selected item to target table
targetTable.getItems().add(selectedPerson);
}
}
对于第二个问题:JavaFX 现在是模块化的,您可以通过 Maven 或 Gradle 获取 JavaFX 依赖项。如果你学习编程,桌面编程总是好的和有趣的。
我正在寻找的重点是获取 tableview1 项目并通过选择 tableview1 行并按加号按钮将其复制到 tableview2 ...
如图所示...
我什么都试过了,但我得到的输出是这样的:
我的代码是:
confirmbutton2.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
itemname2 = tableView1.getSelectionModel().selectedItemProperty().get().toString() ;
tableView1.getSelectionModel().selectedIndexProperty().addListener((num) -> {
itemprice2 = tableView1.getSelectionModel().selectedIndexProperty().get();
itemcount2 = tableView1.getSelectionModel().selectedIndexProperty().get();
});
tableview2.getItems().AddAll(new PersonTransfer(itemname2 , itemprice2 , itemcount2)) ;
检查 TableView1 的第一个选定项目,然后添加到 TableView2。请在
public void onAddItem() {
// check the table's selected item and get selected item
if (table.getSelectionModel().getSelectedItem() != null) {
Person selectedPerson = table.getSelectionModel().getSelectedItem();
// add selected item to target table
targetTable.getItems().add(selectedPerson);
}
}
对于第二个问题:JavaFX 现在是模块化的,您可以通过 Maven 或 Gradle 获取 JavaFX 依赖项。如果你学习编程,桌面编程总是好的和有趣的。