Reputation: 834
I have the following code that I use whenever a user selects a row. Is there any way you can grab the first or the selected cell from the selected row? I need the selected cell because I want the pass that node to the ControlsFX POPOVER.show()
method. I need the popover box
to appear right over the selected row in the tableview
.
tableView.setRowFactory(tv -> {
TableRow<ObservableList> row = new TableRow<>();
row.setOnMouseClicked(event -> {
if (event.getClickCount() == 2 && (!row.isEmpty())) {
popover.show(cellNodeHere<-);
}
});
return row;
});
Upvotes: 0
Views: 1424
Reputation: 834
The solution for me was to use the row as the Node and also turn the arrow location
popup.setArrowLocation(PopOver.ArrowLocation.BOTTOM_CENTER);
This way, the popup shows up right over the TableRow
Upvotes: 1
Reputation: 10969
In your last question just change the row factory to this. You can use getCellData
.
Label label = new Label("click a row");
tableView.setRowFactory(tv -> {
TableRow<ObservableList> row = new TableRow<>();
row.setOnMouseClicked(event -> {
if (event.getClickCount() == 2 && (!row.isEmpty())) {
//if you want the y coord of the row in the scene
double y = ((TableRow)event.getSource()).getLocalToSceneTransform().getTy();
int idx = tableView.getSelectionModel().getSelectedIndex();
label.setText(idx
+ " <-tbl row, idx in items-> "
+ items.indexOf(tableView.getSelectionModel().getSelectedItem())
+ ", first cell-> "
+ ((TableColumn)tableView.getColumns().get(0)).getCellData(idx));
}
});
return row;
});
Upvotes: 1