Platinum Partner
java

Visual Debugging for Swing Apps

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 dev.java.net, 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.

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}