Java SwingWorker while using SWT

杀马特。学长 韩版系。学妹 提交于 2020-01-22 03:50:07

问题


I have a problem as follows:

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);

            }
        }   
    }

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?

Best regards!


回答1:


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.



来源:https://stackoverflow.com/questions/16712988/java-swingworker-while-using-swt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!