我无法提供SSCCE,因为我无法在我的大型应用程序之外重复出错。
但这是一个片段和输出:
if (vp != null) {
try {
starterModule.writePaneln("Sigma.show() 4.1 vp: "+vp);
starterModule.writePaneln("Sigma.show() 4.1 P: "+P);
starterModule.writePaneln("Sigma.show() 4.1 scrollPane: "+scrollPane);
vp.setView(P);
starterModule.writePaneln("Sigma.show() 4.2");
} catch (Exception e) {
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("C:\\javaout2.txt", true)));
out.println("ERROR SIGMA e:");
out.flush();
out.close();
}
}
输出是:
Sigma.show() 4.1 vp: javax.swing.JViewport[,0,0,902x800,layout=javax.swing.ViewportLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=25165832,maximumSize=,minimumSize=,preferredSize=,isViewSizeSet=true,lastPaintPosition=,scrollUnderway=false]
Sigma.show() 4.1 P: javax.swing.JPanel[,0,0,0x0,invalid,layout=javax.swing.BoxLayout,alignmentX=0.0,alignmentY=0.0,border=com.devexperts.dxpro.shared.swing.styles.support.border.DefaultBorderSetter$PaddingBorder@4719dad8,flags=9,maximumSize=,minimumSize=,preferredSize=]
Sigma.show() 4.1 scrollPane: javax.swing.JScrollPane[,0,30,917x800,layout=javax.swing.ScrollPaneLayout$UIResource,alignmentX=0.0,alignmentY=0.0,border=com.devexperts.dxpro.shared.swing.styles.support.border.DefaultBorderSetter$PaddingBorder@14716d46,flags=328,maximumSize=,minimumSize=,preferredSize=,columnHeader=,horizontalScrollBar=javax.swing.JScrollPane$ScrollBar[,0,0,0x0,hidden,layout=com.devexperts.dxpro.shared.swing.styles.laf.impl.basic.StyledScrollBarUI,alignmentX=0.0,alignmentY=0.0,border=,flags=4194632,maximumSize=,minimumSize=,preferredSize=,blockIncrement=10,orientation=HORIZONTAL,unitIncrement=1],horizontalScrollBarPolicy=HORIZONTAL_SCROLLBAR_AS_NEEDED,lowerLeft=,lowerRight=,rowHeader=,upperLeft=,upperRight=,verticalScrollBar=javax.swing.JScrollPane$ScrollBar[,902,0,15x800,layout=com.devexperts.dxpro.shared.swing.styles.laf.impl.basic.StyledScrollBarUI,alignmentX=0.0,alignmentY=0.0,border=,flags=4194632,maximumSize=,minimumSize=,preferredSize=,blockIncrement=10,orientation=VERTICAL,unitIncrement=1],verticalScrollBarPolicy=VERTICAL_SCROLLBAR_ALWAYS,viewport=javax.swing.JViewport[,0,0,902x800,layout=javax.swing.ViewportLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=25165832,maximumSize=,minimumSize=,preferredSize=,isViewSizeSet=true,lastPaintPosition=,scrollUnderway=false],viewportBorder=]
然后程序似乎冻结在vp.setView(P)上;因为没有调用下一个writePaneln。
但是,错误也没有被困......
这里写了paraneln(完整性)
public static void writePaneln(String txt){
if(DEBUG){
try {
synchronized (textPane) {
//textPane.getDocument().insertString(textPane.getDocument().getLength(), txt + "\n", null);
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("C:\\javaout.txt", true)));
out.println(txt);
out.flush();
out.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(null,"writePaneln ERROR: "+e);
}
}
}
编辑1
我已经改为在java.util.timer中使用invokeLater:
class RemindTask extends TimerTask {
@Override
public void run() {
SwingUtilities.invokeLater(
new Runnable(){
@Override
public void run() {
handleGO();
};
}
);
}
}
答案 0 :(得分:1)
使用引用here的方法之一来查找违反EDT的内容。
我应该将
CheckThreadViolationRepaintManager
放入工厂吗?
如图here所示,您可以将RepaintManager
替换为CheckThreadViolationRepaintManager
的实例以捕获违规行为。
RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager());
答案 1 :(得分:1)
如果调用线程既不返回也不抛出异常,那么它显然会被卡在某处。 你可以尝试两件事:
setView
调用开始发生的事情(由@DeltaLima建议)我建议从2.开始,因为它便宜又快捷。
祝你好运。