1

I CANNOT provide an SSCCE as I can't make error repeatable outside of my large App.

But here is a snippet and the output:

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

Output is:

    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=]

Then the program appears to freeze on vp.setView(P); as the next writePaneln is not called.

HOWEVER, the error is not trapped either....

Here writePaneln ( for completeness)

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

EDIT 1

I have changed to using invokeLater in my java.util.timer:

        class RemindTask extends TimerTask {

               @Override
               public void run() {
                   SwingUtilities.invokeLater(
                           new Runnable(){

                               @Override
                                public void run() {
                                   handleGO();
                                };
                           }
                   );
               }
       }
ManInMoon
  • 6,795
  • 15
  • 70
  • 133
  • sounds like a EDT violation - all access to swing components _must_ happen on the EDT. That being the case, there either is no need to synchronized on the textPane (you are on a single thread, that is the EDT) or you are violating the rule – kleopatra Dec 05 '13 at 09:32
  • @kleopatra I tried removing synchronized (textPane) and I get SAME error – ManInMoon Dec 05 '13 at 09:35
  • 1
    removing that is not the point (sorry for having been unclear) - you have to make certain that _each and every_ access to a swing component is on the EDT (to learn more, have a look f.i. into the concurrency chapter of the tutorial referenced in the Swing tag wiki, click the info tab) – kleopatra Dec 05 '13 at 09:38
  • @kleopatra is correct; use one of the approaches cited [here](http://stackoverflow.com/q/7787998/230513) to find violations. – trashgod Dec 05 '13 at 10:12
  • @trashgod CheckThreadViolationRepaintManager has only a comment in it - is that meant to be? Also I do not have access to Main (my code is uplaoded into a greater App) Should I put CheckThreadViolationRepaintManager in Factory? – ManInMoon Dec 05 '13 at 10:34
  • @kleopatra I am using a java.util.timer. Do you think if I use invokeLater that will make it run on EDT - see EDIT 1 – ManInMoon Dec 05 '13 at 10:57
  • replace the util.Timer by swing.timer, that will guarantee execution on the EDT (and don't forget to read the tutorial/api doc :-) – kleopatra Dec 05 '13 at 11:01
  • In cases like this it might help to attach a debugger an dive into the code step by step. It can be a long and frustrating process but there is good change that you will find where things go wrong. Unless it is a Heisenbug of course :-) – DeltaLima Dec 05 '13 at 11:05
  • @kleopatra I stayed with java.util.timer but used invokeLater as in my EDIT 1. That seems to have solved the issue. Thank you for putting me on the right track. – ManInMoon Dec 05 '13 at 13:10
  • updates from util.Timer is synchronous for JVM, asynchronous for EDT, invalid status from exception talking about JComponents is intialized, but isn't isDisplayable because its child(s) is/aren't intialized, use JProfiler, there you can to see all signals, finally (I'm sure untill there if isn't there overode custom RepaintManager, then stop this code block) this exception haven't something with JViewport – mKorbel Dec 05 '13 at 14:15

2 Answers2

1

Use one of the approaches cited here to find EDT violations.

Should I put CheckThreadViolationRepaintManager in Factory?

As shown here, you can replace the RepaintManager with an instance of CheckThreadViolationRepaintManager to catch violations.

RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager());
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
1

If the calling thread neither returns nor throws an exception, it is obviously stuck somewhere. You can try two things:

  1. Attach a debugger and see what happened starting from the setView call (as suggested by @DeltaLima)
  2. Run the thing and create a thread dump (instructions differ based on OS, unfortunately you didn't mention yours). The thread dump will show you exactly where your program is stuck and why it is stuck, i.e. what other thread may hold a lock that yours wants.

I'd recommend to start with 2., as it is cheap and quick.

Good luck.

Hendrik
  • 5,085
  • 24
  • 56