如果最小化,Swing 应用程序会崩溃

Swing app crashes if minimised

我的 swing 应用程序有问题。

我有一个 SwingWorker,里面有一个 for 循环,它启动 300 多个 oracle 数据库请求并用结果填充几个 JTable

如果我保持 swing 应用程序 window 未最小化,或者至少在 windows 资源管理器中部分可见,则批处理可以正常完成。现在,如果我最小化该应用程序,然后返回到 swing 应用程序,它将被冻结。

组件的基本轮廓和颜色将可见,大部分 window 将只是我为其设置的背景颜色(黑色),并且不会显示任何文本。终止应用程序的唯一方法是终止进程,因为我单击 'X' 按钮不会关闭 window。

这是一个常见问题吗?你是如何预防的?

批处理工作器中的循环:

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

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

这可能是问题的根源。 SwingWorker relies on calling publish() in doInBackground() and using process() to update the TableModel on the event dispatch thread. A complete example is examined .