Thursday, June 28, 2012

A Swing window is just as transparent as a web page

I'm a fan of the web and I admire how powerful the browser has become. Since I'm almost always in a browser (even to type this blog) I would certainly love to see even more useful apps, like, perhaps, an online IDE. So, although I work with desktop apps I like this cloud and web app kool-aid a whole lot.

One of the advantages I see in web apps is how transparent they are. It's all text, with code in an easy scriptable language. It's easy to inspect and change. Easy to deploy.

But I don't work with web apps. I work with large desktop Swing applications, usually on top of the NetBeans Platform.

I routinely debug these Swing apps with the debugger, VisualVM, BTrace and simple apps or unit-tests that reproduce the issue.

And it occurred to me after a debugging session to me that Swing apps are quite transparent too! The fact that Java code is compiled is just a decoy. As a developer you have access to the source code anyhow but, even as an user, you have about the same freedoms as you have with a web app.

Just as I could look into the DOM hierarchy in the browser, I have the Swing hierarchy of components.

Just as I could add my own Javascript event handlers, I have Swing listeners.

Although existing code is compiled, I could make a small BTrace script to see its execution and inspect parameters and values.

Without having to recompile, I can easily use reflection to look into private data and even tweak it.

So, although Swing would seem pure binary, there is nothing you don't have access to. It's an open book!


Alex Kotchnev said...

A long, long time ago, when I was messing around w/ Groovy & Jemmy (eg. to automate clicking buttons on a GUI, I remember that there was even a plugin that could show you the component hierarchy. Throw in a little groovy script like in that blog post, and you have the equivalent of firebug.

Antonio said...

Maybe Swing windows are just as transparent as web pages, but the real issue is that Java virtual machines are not as transparent as web browsers. And that's a pity.