蜡染画布的getUpdateManager返回null

时间:2018-09-27 15:26:56

标签: java swing batik

使用蜡染从 UpdateManager 获取 JSVGCanvas 时,它将返回 null

public void init() {
    canvas = new JSVGCanvas(null, true, false);
    canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
}

public void paint(final DomainObject domainObject) {
    UpdateManager updateManager = canvas.getUpdateManager();
    RunnableQueue runnableQueue = updateManager.getUpdateRunnableQueue();
    runnableQueue.invokeLater(new Runnable() {
        public void run() {
            // Document operations here
        }
    });
}

如何管理此错误?

1 个答案:

答案 0 :(得分:0)

绘画方法必须分为两部分,一个是将GVTTreeRendererListener注册到JSVGCanvas对象。渲染完成后,此侦听器将调用执行实际绘画工作的方法,届时,画布中将出现UpdateManager对象。

public void init() {
    canvas = new JSVGCanvas(null, true, false);
    canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
}

public void paint(final DomainObject domainObject) {
    canvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter() {
        public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
            renderComplete(domainObject);
        }
    });
}

public void renderComplete(DomainObject domainObject) {
    UpdateManager updateManager = canvas.getUpdateManager();
    RunnableQueue runnableQueue = updateManager.getUpdateRunnableQueue();
    runnableQueue.invokeLater(new Runnable() {
        public void run() {
            // Document operations here
        }
    });
}

免责声明: 在这个蜡染布论坛中找到了答案,我决定在此处将其记录为更有用的资源http://batik.2283329.n4.nabble.com/UpdateManager-is-Null-td2974717.html