如果最小化,Swing 应用程序会崩溃 [英] Swing app crashes if minimised
问题描述
我的 Swing 应用程序出现问题.
我有一个 SwingWorker
,里面有一个 for 循环,它启动 300 多个 oracle 数据库请求并用结果填充几个 JTable
.
如果我保持 Swing 应用程序窗口未最小化,或者至少在 Windows 资源管理器中部分可见,则批处理可以正常完成.现在,如果我最小化应用程序,然后返回到 Swing 应用程序,它将被冻结.
组件的基本轮廓和颜色将可见,大部分窗口将只是我为其设置的背景颜色(黑色),并且看不到任何文本.终止应用程序的唯一方法是终止进程,因为我点击X"按钮不会关闭窗口.
这是一个常见问题吗?您如何预防?
在批处理器内部循环:
for(int i=1; i<=maxDepth; i++){String[] 结果 = getAllLists(database, i);for(int j=0; jqueryResult = 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(句号);}别的{System.out.println("查询无效");}}}}
我不在代码中的任何地方使用
publish
和process
.
这很可能是问题的根源.
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 JTable
s 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");
}
}
}
}
I don't use
publish
andprocess
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.
这篇关于如果最小化,Swing 应用程序会崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!