Skip to main content

Swing testing and debugging on JavaOne

Posted by alexfromsun on June 28, 2006 at 9:40 AM PDT

Hello everybody !

After spending a fantastic after JavaOne vacation, travalling Arizona and Florida I am happy to say hello to the comminity again.
Thanks to everyone who visited JavaOne and especially who visited my BOF session about Swing testing and debugging.


I'd like to underline that it were you guys who gave me much of the ideas to complete the presentation.

Thank you once again and let me add two little debugging-related addons which I didn't mention earlier:

CTRL+SHIFT+F1

I was really surprised when AWT guys told me about this funny feature, because I hadn't ever used it before.
So, this combo is hardcoded in java.awt.Window.preProcessKeyEvent() method and is used to dump the list of children of this window to System.out.

For example if you press CTRL+SHIFT+F1 when an empty JFrame is active and check the console
you'll discover the compound nature of JFrame:

    javax.swing.JFrame[frame0,0,0,200x200,layout=java.awt.BorderLayout,title=,resizable,normal,defaultCloseOperation=EXIT_ON_CLOSE,rootPane=javax.swing.JRootPane[,4,28,192x168,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
     javax.swing.JRootPane[,4,28,192x168,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=]
      javax.swing.JPanel[null.glassPane,0,0,192x168,hidden,layout=java.awt.FlowLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777217,maximumSize=,minimumSize=,preferredSize=]
      javax.swing.JLayeredPane[null.layeredPane,0,0,192x168,alignmentX=0.0,alignmentY=0.0,border=,flags=0,maximumSize=,minimumSize=,preferredSize=,optimizedDrawingPossible=true]
       javax.swing.JPanel[null.contentPane,0,0,192x168,layout=javax.swing.JRootPane$1,alignmentX=0.0,alignmentY=0.0,border=,flags=9,maximumSize=,minimumSize=,preferredSize=]

-Xbootclasspath

This might be a well known feature, but I'd like to mention it here despite the fact it's not related to Swing directly.

In the presentation I collected some useful debugging techniques, but what if you tried everyting and still don't find a bug?


With help of -Xbootclasspath you can substitute any core classes from JDK and add as many System.out.println as you want.

For instance:

  1. Create java/awt folders and put there the Component.java from JDK
  2. Add System.out.println(this) to the very beginning of requestFocusHelper() method
  3. Compile this class
  4. Run your application as java -Xbootclasspath/p: YourApplication

After that you'll be notified when any Component.requestFocusXXX() is invoked

This technique is very helpful for our dear JDK contributors, because it makes it so easy to test updated JDK on any OS with the installed JDK remains intact

Afterword

Don't forget to check out SwingHelper project
and send your valuable comments either to the project's mailing lists or leave it here.

Please share your ideas how to make Swing testing and debugging easier
and what we should add to the next version of JDK to prevent Swing programmers from all that tricky bugs !

Related Topics >>