Swing testing and debugging on JavaOne
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:
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:
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.
- Create java/awt folders and put there the Component.java from JDK
- Add System.out.println(this) to the very beginning of requestFocusHelper() method
- Compile this class
- Run your application as java -Xbootclasspath/p:
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
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 !