java - How Can I Add TableView1 items to TableView2?
问题描述
The point that I'm looking for, is to getting tableview1 items and kind of coping it to tableview2 by selecting the tableview1 row and pressing the plus button ...
as you can see in the picture ...
I Have tried everything but the output that I get it's like this:
my code is:
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)) ;
解决方案
Check first selected item of TableView1 then add to TableView2. Please see the full TableView sample code in this answer.
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);
}
}
For second question: JavaFX is now modular and you can get JavaFX dependencies via Maven or Gradle. Desktop programming is always good and fun if you learn programming.
推荐阅读
- python-3.x - 从 CSV 文件中删除标题
- javascript - 如何使用 JavaScript 将文本从一个字段复制到另一个选项卡菜单的字段?
- php - 致命错误:在布尔值上调用成员函数 getData()
- python - ColumnTransformer 和 FeatureUnion 之间的 Scikit-Learn 管道代码差异
- android - android studio 导入 GreenDao 后无法解析 DaoMaster
- c++ - Valgrind 插入排序的大小为 8 的无效读取
- image - 更改图片时如何销毁缓存图像
- ios - 错误 ITMS-90730ITMS 无法在 Xcode 10.2.1 中上传 IPA
- bootstrap-4 - Bootstrap-4 脚本的最佳位置和脚本的标签
- python - 当“pip3 install mysqlclient”时,如何在我的 Mac 上修复“ld: library not found for -lxxx”?