使用SWT时使用Java SwingWorker [英] Java SwingWorker while using SWT

查看:107
本文介绍了使用SWT时使用Java SwingWorker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,如下:

我编写了一个简单的简约应用程序,该应用程序将SWT用于GUI. 在特定的选项卡中,它显示一个表,该表通过REST Api调用填充了Informition.另外,我还有另一种方法可以将此表导出为CSV文件. 这绝对好用.现在,我需要某种自动更新/导出,为此我实现了这样的Swing-Worker:

I've written a simple minimalistic Application that utilizes the SWT for the GUI. In a specific tab, where it displays a table that get's filled with Informition via a REST Api Call. Additionaly, i have another method to export this table into a CSV-file. This works absolutely fine. Now I need some kind of autoupdate/-export for which I implemented a Swing-Worker like this:

    protected class AutoExportWorker extends SwingWorker<Integer, String> {


    @Override
    public Integer doInBackground() throws Exception {


        System.out.println("Worker Start!");

        while (true) {
            System.out.println("In Loop");

                            //updateTable();
                            //exportToCSV();

            for (int i = 0; i<interval;i++) {

                System.out.println(interval - i);
                Thread.sleep(1000);

            }
        }   
    }

该类是Composite的子类,该类查看表并保存方法"updateTable()"和"exportsToCSV()".现在,我知道当我调用这些方法时,该工作人员并没有做很多事情,但是我不知道如何正确执行此操作.你对我有什么提示吗?

The Class is a subclass of the Composite which views the table and holds the methods "updateTable()" and "exportsToCSV()". Now I'm aware that this Worker doesn't do much when I call these Methods but I can't figure out, how to do this correctly. Do you have any hints for me?

最诚挚的问候!

推荐答案

如果使用的是Eclipse RCP,则应使用 Display.asyncExec 来更新表.

If you are using Eclipse RCP, you should use Jobs API. In plain SWT, there is no built-in solution. You need to use Display.asyncExec to update the table.

这篇关于使用SWT时使用Java SwingWorker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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