在JavaFX中发布渲染事件 [英] Post render event in JavaFX

查看:94
本文介绍了在JavaFX中发布渲染事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将click事件侦听器添加到TableView的所有列标题的标签中,如下所示:

I'm trying to add a click event listener to the label of all column-headers of a TableView, as follows:

for (final Node header : tblView.lookupAll(".column-header > .label")) {         
    if ((header != null) && (header instanceof Label)) {
        final Label headerLabel = (Label) header;
        // ...
    }
}

现在,问题在于,如果我在Controller的initialize()函数中执行此操作,则不会渲染Scenegraph,并且上述代码将无法正常工作.因此,我的问题是:是否存在某种后期渲染事件?

Now, the problem is that if I do this in the initialize()-function of the Controller, the Scenegraph is not yet rendered and the above code won't work. Hence my question: Is there some kind of a post-render event?

非常感谢.

推荐答案

Stage(从Window扩展)中添加事件处理程序,以类似的方式使用它.

There is a WINDOW_SHOWN event in javafx.stage.WindowEvents. That is not (imo) "Post render event" but you can utilize it in similar manner, by adding an event handler to the Stage (which extends from Window).

在控制器类的initialize方法中,获取主要阶段,然后:

In the initialize method of controller class, get the primary stage and then:

stage.addEventHandler(WindowEvent.WINDOW_SHOWN, new EventHandler<WindowEvent>() {
    @Override
    public void handle(WindowEvent window) {
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                addListenerToColumnHeaders();
            }
        });
    }
});

希望这会有所帮助,因为我没有尝试过自己.

Hope this helps, since didn't try myself.

这篇关于在JavaFX中发布渲染事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆