Reputation: 145
Is there any Mouse click event for TableColumn in Java FX ? I can see it in tableView but not in TableColumn. Please suggest.
Upvotes: 1
Views: 1697
Reputation: 209340
There's no particularly nice way to do this. Probably the best option is not to set text on the column, but to set the graphic to a Label
containing the desired text instead. Then register the mouse listener with the Label
.
Using the standard Oracle tutorial as an example, you could do:
TableColumn<Person, String> firstNameColumn = new TableColumn<>();
Label firstNameColHeader = new Label("First Name");
firstNameColHeader.setOnMouseClicked(e -> System.out.println("Click on header"));
firstNameColumn.setGraphic(firstNameColHeader);
Note that this will break the table menu button, if you use it, because the options in the menu use the text from the TableColumn
, which is no longer present.
Upvotes: 1