Swing app crashes if minimised

夙愿已清 提交于 2019-12-24 09:27:11

问题


I have a problem in my swing app.

I have a SwingWorker that has a for loop inside, that launches 300+ oracle database requests and populates several JTables with the results.

If I keep the swing app window not-minimised, or at least partly visible in the windows explorer, the batch completes fine. Now, if I minimise the app, and then go back to the swing app, it will be frozen.

Basic outline and colours of the components will be visible, most of the window will be just of the background colour I set to it (black) and no text will be visible. The only way to kill the app is by killing the process, since I clicking on 'X' button will not shut the window down.

Is this a common issue? How do you prevent it?

Loop inside the batch worker:

for(int i=1; i<=maxDepth; i++){
    String[] result = getAllLists(database, i);
    for(int j=0; j<result.length; j++){
        String period=result[j];
        for(String name : names){
            System.out.println("New Query: "+name+ " " + period + " | " + "Loading " + (days) + " days x " + years + " years --- ");
            if(isValid(period,name)){
                List<TickHistory> queryResult = model.getByDaysMultiple(name,period,days+mod+daysHeadroom,years, false);
                getModelTableData(name, period, DatabaseHelpers.dateToString(lastCob), years,days,queryResult);
                populatePricesTable(queryResult, days, false);
                view.setNameText(name);
                view.setPeriodText(period);
            }else{
                System.out.println("query invalid");
            }
        }
    }
}

回答1:


I don't use publish and process anywhere in my code.

This is a likely source of the problem. SwingWorker relies on calling publish() in doInBackground() and using process() to update the TableModel on the event dispatch thread. A complete example is examined here.



来源:https://stackoverflow.com/questions/38499282/swing-app-crashes-if-minimised

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