Reputation: 307
I have a ComboBoxTableCell in my TableView, when someone click the ComboBoxTableCell, I want that another Pane will display below the ComboBoxTableCell with a list of items. I tried to get the coordinate of the ComboBoxTableCell but no luck. Is there any way to get the coordinate? Or Do you have any better way to do this? Below is the image of Sample UI, I want to be done. Thanks.
Here is my method to initialize the TableView
private void initOrderTable(){
this.orderTable.setEditable(true);
TableColumn nameCol = new TableColumn("Name");
nameCol.setMinWidth(100);
nameCol.setCellValueFactory(
new PropertyValueFactory<>("name"));
nameCol.setCellFactory(new Callback<TableColumn<Product, String>,ComboBoxTableCell<Product,String>>() {
@Override
public ComboBoxTableCell<Product, String> call(TableColumn<Product, String> param) {
ComboBoxTableCell ct= new ComboBoxTableCell<>();
ct.setComboBoxEditable(true);
return ct;
}
});
this.orderTable.getItems().addAll("Sample Row");
this.orderTable.getColumns().addAll(nameCol);
}
Upvotes: 0
Views: 1584
Reputation: 209694
You can get the coordinates of the cell relative to the Scene
with
Point2D location = ct.localToScene(0, 0);
or relative to the Screen with
Point2D location = ct.localToScreen(0, 0);
Those will give you the coordinates of the top left of the cell. You can do
Point2D location = ct.localToScene(0, ct.getHeight());
to get the coordinates of the bottom left relative to the Scene
, etc. Obviously you will need to set a listener on the cell to be invoked when you need to show the pane.
Upvotes: 1