gpt4 book ai didi

java - JViewport.setView 无法捕获的错误

转载 作者:行者123 更新时间:2023-11-30 04:07:29 26 4
gpt4 key购买 nike

我无法提供 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 没有被调用。

然而,错误也没有被捕获......

这里 writePaneln (为了完整性)

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

最佳答案

使用引用的方法之一 here查找 EDT 违规行为。

Should I put CheckThreadViolationRepaintManager in Factory?

如图here ,您可以将 RepaintManager 替换为 CheckThreadViolationRepaintManager 的实例抓获违规行为。

RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager());

关于java - JViewport.setView 无法捕获的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20395528/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com