English 中文(简体)
Swing Generator
原标题:

I need to develop some java gui using swing.
A few years ago I did develop a bit with swing.
But it was pretty exhausting, you see, back than there weren t much tools to help you.

But I do believe today it should be easier, there must be tools.
I would like to use some kind of a generator or maybe a utility or even a framework.
I know Eclipse has a few plugins and Netbeans has a nice built in tool. I have also heard good things about Jide framework.

But still, I don t really know any of them.

Is there a tool/Utility/Generator/Framework that you have used and really helped you?

Obviously I would prefer something that is free, but if you know something that is really really good and cost money, that could work too.

Thank you.

问题回答

Actually the faster way to write Swing frames that I ve found so far is to use Groovy SwingBuilder but you have to include groovy s jar inside your project to use it. This is an example taken from their website, it s mainly synctactic sugar but it helps:

def frame = swing.frame(title: Frame , defaultCloseOperation:JFrame.EXIT_ON_CLOSE, pack:true, show:true) {
    vbox {
        textlabel = label("Click the button!")
        button(
            text: Click Me ,
            actionPerformed: {
                count++
                textlabel.text = "Clicked ${count} time(s)."
                println "Clicked!"
            }
        )
        widget(sharedPanel())
        widget(sharedPanel())
   }
}

Otherwise there are some "visual" approach to the problem but they don t let you integrate so quickly with the interface you wrote (for example jvider), NetBeans and Eclipse have some plugins to do the dirty work but as before: you can t integrate so seamlessy.

For quite a few years I ve used NetBeans built in "Matisse" form editor. It s got the advantage of being built into the IDE, so that the form editing and code generation is rather seamless. If you re new to Swing it can be a big boost (as long as you continue to use NetBeans as your IDE).

There are some issues, however:

  1. You can t easily move a form to another IDE. The generated code may work, but the form data itself is stored an XML file.
  2. If two more people edit a form at the same time, conflicts can arise in SVN/CVS that are nearly impossible to reconcile. The XML is not really human readable.
  3. In the past I found the form XML file to corrupt itself, which would lead to form generation errors.
  4. The form editor can get a mind of its own sometimes, destroying your arrangement when you do something as simple as resize a control.

In spite of all the above, I ve continued to use it as nothing else has seemed appealing to me.

My suggestion would be WindowBuilder Pro. It s a GUI designer that comes as a plugin for the Eclipse IDE.

You can use it to generate Swing, SWT or GWT GUIs and even generate some Eclipse RCP code if you need to. I must say that it works quite well for me. I haven t used it to generate any Swing code, though, as I prefer to work with SWT instead.

In terms of GUI Builders, NetBeans and IDEA (now going open source with the 9.0 Beta) both have free GUI Builders.

GUI Builders have all the kinds of downsides that Jason spoke to. If you want good control over what is going on, but still want something sane to write a complex GUI by hand, check out MigLayout.

Eclipse s Visual Swing is a promising upstart. It isn t the most stable thing in the world, but it does all the form stuff in code, so there are no separate files which are hard to read and merge in source control. When you first try it, it takes some getting used to. But once you learn to work around the bugs you pretty rapidly develop Swing GUIs.

I would go w/ matisse if you wnat to use a gui builder, and there are shortcomings as Jason mentioned, but you also need to include a jar file that is used by the matisse layouts, this may or may not be a problem.

But if you are going to be developming UI s in swing, you will soon come to find out most of the gui builders have many shortcomings, and when you have to change something the generated code is not always clear and is bloated. You will also find that once you become proficient you can write a ui much faster by hand than the gui builder, and you will really understand what is going on.

So I say stay away from gui builders, you will create better and more maintainable UI s, and w/ some time and experience will not want to use a gui builder. Just start w/ some of the basic Swing tutorials on layout.

May I humbly suggest Metawidget?

It takes a different approach to UI development - removing much of the error-prone, tedious work whilst still retaining the flexibility of traditional toolkits. It integrates with your existing front-end (Swing, in your case) and back-end (Java, I m guessing), and works at runtime (no code generation).

There s a few short intro videos here:

http://metawidget.org/videos.html

If you get chance to take a look, I d be most grateful for your feedback.

Regards,

Richard.

You can avoid GUI builders generated code by using ReflectionUI.

Advantages: you instantly generate your GUI and then you customize it visually (or with few code if you need something very specific).





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签