I would like to ask your opinion[s] about how to approach the problem of generating Swing application UIs at runtime. And, to start: I am writing a Swing client application - not an applet and not a browser-based application.

My IDEAL user experience would be to simply display DHTML in something like a JEDitorPane - but that doesn't work because

1) my UI is fairly complicated (perhaps too complicated for a JEditorPane) and
2) more importantly, JEditorPanes do not handle JavaScript. Thus, there is no way for the application to interact with the UI elements (e.g., to highlight a button or to get an indcation that a checkbox was clicked).

I've looked at LOBO/COBRA, but the COBRA library does not render pages well [yet?]. It certainly is not up to what one sees in a regular browser.

I looked at Flex from Adobe, but I'm concerned about the deployment of AIR. I don't have any data as to how widely it's deployed versus JVMs.

So I'm pretty much resigned to just using normal Swing controls , perhaps modified with a better skin/look and feel than the default. What I need to do is to be able to generate the UI at runtime by reading a set of directives - XML, for example. I thought JAXX would do the trick, but it appears that JAXX is really a tool for implementing controls and their wiring at compile-time and not what I'm looking for.

I've seen the documentation for XUL, but I don't see any classes or libraries that can read and parse XUL and create Swing controls at runtime.

So, I want something fairly lightweight, easy to use, open-source and fairly well maintained. I've scoured the web looking for a solution and have found none and I'm almost resigned to writing my own runtime system to read and parse XML and then execute code to create controls on the fly...but this is not a trivial task.

It seems to me that with the advent of rich client UIs, I can't be the only one facing these issues. Does anyone have a suggestion? Am I missing something?

Thanks!

why do you want to generate your UI at runtime?

if you want to use XML you could write your own parser, for this you would probably need to use DOM.

as for actually creating a UI at runtime, i don't know exactly how you would go after that, you may have to write your classes that encapsulate swing classes, so that you don't have to know, at compile-time what your adding to what, just so that you don't have to hard-code that your going to be adding something to a JPanel, because your application may not be adding it to a JPanel, it might be adding it to a JFrame, or a JTabbedPane, etc..

i think you have a lot of work ahead of you, good luck to you.

Thanks for the reply...

People generate UIs at runtime all the time - that is, after all, what web browsers do. I point my browser at an URL and I see a particular interface, but I can return next week and the company has changed the entire layout of their pages. Web developers can simply modify HTML emitted in their .asp or .jsp files and - voila - they have a new look and feel.

However, there are a LOT of people moving away from browser-based applications (because of real or perceived security threats or incompatibilities between browsers) and more to rich internet client applications using tools like Flex and Air. Adobe makes some good points about this kind of programming. And people have been writing applications this way for ages; H&R Block TaxCut comes to mind. Since some tax rules aren't finalized until after January 1, but the tax software has to be ready for sale by that date, the program uses a custom, form-based method for generating the UI at runtime. And the forms themselves can be modified for months (which is why TaxCut checks for updates).

Also, separating UI code from program logic can be thought of as yet another "tier" and may provide additional security, flexibility or portability. In any case, I don't have a choice - this is what I have to do. The only thing I can think of is reading XML, parsing it, and, basically, using a giant Switch-Case construct based on the desired control type to create the desired Swing objects.

I finally located something called SwiXML last night and I'm evaluating that, but the documentation is very sketchy. Again, suggestions are appreciated.

when you say UI your referring to the actual pages, the my understanding of the UI would be the back button, and toolbars. generating a web page is done automatically by the JEditorPane when setPage() is used. but actually making a full GUI with frames panels buttons and such is still not going to be easy.

i was going to suggest the giant switch statement, but with that how do you intend to keep track of what contains what (component) which components are where.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.