Geertjan is a DZone Zone Leader and has posted 468 posts at DZone. You can read more from them at their website. View Full User Profile

Visual Debugging for Swing Apps

  • submit to reddit

Two days ago, the 1.0 release of the Swing Explorer was announced. It is a handy tool for examining an application's component hierarchies, properties, events, and threads.

Swing Explorer, yet another cool application available on, is handy when debugging your Swing application. In some ways, it is comparable to an AST Viewer, except that it displays component hierarchies instead of an abstract syntax tree. Just as an AST view is crucial when working with the internals of a language, so the Swing explorer is essential in understanding the relationships between components in a Swing application. Below is a case in point, the explorer view on the left showing the complete hierarchy of the application under observation:

Of course, an IDE or GUI Builder would provide a similar view. The difference is that, in this case, the above application is deployed from a JAR outside of an IDE. In other words, the application is not in development/production mode, although it could be too. The Swing Explorer starts up your application with this command:

java -javaagent:swag.jar -Xbootclasspath/a:swag.jar -cp swexpl.jar;<your_class_path> org.swingexplorer.Launcher <your_main_class>

And that's it. Your own application then starts up, as does the Swing Explorer. Then you can explore the application in the way shown above. Not only the component hierarchy of the application is then exposed, but also all its properties, such as its layout and borders. The tabs at the bottom are very useful too. The "Player" tab lets you observe the order in which the application is constructed and the content is drawn. Some questions that you can have answered by means of the Swing Explorer:

  • "I do not see a component on my JFrame. However, it should be there."
  • "My colleague developed a panel two years ago. I have no idea how it is constructed. I'd like to figure out why a component appears on this place? Why it is shifted 5 pixels to the left?"
  • "I want to debug my application in a Java debugger step by step and watch what each step produces on the screen when I add components into my JFrame."
  • "I see a small dot in the upper right corner, why it is there?"
For info on these and related usecases, see Getting Started with Swing Explorer.

The "AWT Events" and the "EDT Monitor" tabs are new, providing useful information on AWT and EDT, with further finegrained filtering planned for future releases. Here's the EDT Monitor in action:

The plan to provide plugins for Eclipse and NetBeans IDE is also an interesting one. Swing user interface debugging--seems like this tool is perfectly attuned to this need.

swing-explorer-in-action.png97.39 KB
edt-tab.png60.64 KB
Published at DZone with permission of its author, Geertjan Wielenga.


Shay Shmeltzer replied on Wed, 2008/04/16 - 11:48am

The Free Oracle JDeveloper has had such a visual Swing debugger for a long time.

A basic introduction to it is here:

 The nice thing here is that it is not an external tool but rather an integral part of your IDE.


Our developers use it to debug JDeveloper itself - which after all is just another Swing application. 

Geertjan Wielenga replied on Wed, 2008/04/16 - 11:53am

Probably every IDE has such a thing. However, as pointed out in this article, this particular application is not part of an IDE. This has several advantages, such as the fact that it is lightweight and it is useful for debugging JAR files for which you might not even have the sources available.

Shaul Goral replied on Wed, 2008/04/16 - 1:11pm

How do you debug a JAR file that you don't have the sources for? if you don't have them you can't change them.

Do you mean get ideas from it?

Shay Shmeltzer replied on Wed, 2008/04/16 - 5:08pm in response to: Geertjan Wielenga

[quote=geertjan]Probably every IDE has such a thing. [/quote]

I don't think so - AFAIK the only IDE with this is JDeveloper. 

Maxim replied on Thu, 2008/04/17 - 5:04am

Geertjan, thanks for promoting Swing Explorer :), really nice article. About 2 years ago I've created a first small prototype of Swing Explorerand after that I discovered that JDeveloper has quite similar thing. But for my work I mainly use Eclipse and Netbeans and I needed such functinality anyway. So I decided to create Swing Explorer as a small 1 Jar file that is easily runnable from any IDE. In Eclipse you just need to create a new Run configurationwith parameters. As I know JDeveloper does not support all features included in SwingExplorer and vice versa. For instance JDeveloper had no support something like "Player" in Swing Explorer when I evaluated it. Actually this functionality I'm most proud of.

Maxim Zakharenkov (Developer of Swing Explorer)

P.S. If you are going to visit Java One 2008, we'll have a separate BOF session about different swing application debugging techniques, so everybody is welcome. See more info here: BOF-5063

Geertjan Wielenga replied on Thu, 2008/04/17 - 2:52pm

@Shay: wow that stuff in JDeveloper looks cool. I think I might take JDeveloper for a spin soon especially for that reason.

@shaulgo: you're right, without the sources debugging would be problematic. However, I really like the idea of being able to look at the internals of a Swing app where I would simply have the JAR and nothing else. Just for the fun of it, but I'm guessing there'd be practical reaons too.

@Maxim, congrats with this cool tool and hope to catch up with you at JavaOne! 

Myk Bova replied on Tue, 2008/07/22 - 2:26pm

Thanks a lot!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.