我需要在表视图中添加一个FilterButton过滤器选项,但是在执行初始化方法时该表视图不存在,导致以下代码报告错误。
@Override
public void initialize(URL location, ResourceBundle resources) {
final ContextMenu menu = new ContextMenu();
menu.getItems().addAll(showHideidUrl);
final Node showHideColumnsButton = tableView
.lookup(".show-hide-columns-button");
EventHandler<MouseEvent> mousePressedHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if (menu.isShowing()) {
menu.hide();
} else {
menu.show(showHideColumnsButton, Side.BOTTOM, 0, 0);
}
event.consume();
}
};
showHideColumnsButton.addEventFilter(MouseEvent.MOUSE_PRESSED,
mousePressedHandler);
}
我的测试仪不使用以下事件监视。
tableView.sceneProperty().addListener((observableScene, oldScene, newScene) -> {
if (oldScene == null && newScene != null) {
newScene.windowProperty().addListener((observableWindow, oldWindow, newWindow) -> {
if (oldWindow == null && newWindow != null) {
final ContextMenu menu = new ContextMenu();
menu.getItems().addAll(showHideidUrl);
final Node showHideColumnsButton = tableView
.lookup(".show-hide-columns-button");
EventHandler<MouseEvent> mousePressedHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if (menu.isShowing()) {
menu.hide();
} else {
menu.show(showHideColumnsButton, Side.BOTTOM, 0, 0);
}
event.consume();
}
};
showHideColumnsButton.addEventFilter(MouseEvent.MOUSE_PRESSED,
mousePressedHandler);
}
});
}
});
有什么方法可以监视tableview显示的执行情况?