Reputation: 41
I want to customize the button of the tableview, but it is empty when I get the show-hide-columns-button in the initialize method. There is a way to get the show-hide-columns-button.
@FXML
private TableView tableView;
@Override
public void initialize(URL location, ResourceBundle resources) {
tableView.setTableMenuButtonVisible(true);
final Node showHideColumnsButton = tableView
.lookup(".show-hide-columns-button");
System.out.println(showHideColumnsButton);
}
Upvotes: 1
Views: 68
Reputation: 4258
As mentioned in the comments, a call to lookup(".show-hide-columns-button")
returns null if the Scene
is not shown yet. A simple solution:
tableView.sceneProperty().addListener((observable, oldScene, newScene) -> {
if (newScene != null) {
newScene.windowProperty().addListener((obs, oldWindow, newWindow) -> {
if (newWindow != null) {
newWindow.addEventHandler(WindowEvent.WINDOW_SHOWN, event -> {
final Node showHideColumnsButton = tableView.lookup(".show-hide-columns-button");
// Customize your node here...
showHideColumnsButton.setStyle("-fx-background-color: red;");
event.consume();
});
}
});
}
});
Upvotes: 0