开发者

Netbeans: using GUI Builder on regular Java class file

I'm using Netbeans. When I create a Java class, I sometimes want to change it to be a GUI component so that I can visually edit it using the GUI Builder.

What is the 开发者_如何学Gonecessary step to transform a regular Java class to a GUI component so that Netbeans would recognize it and allow me to use GUI Builder ? (i.e. switch between Source and Design)


NetBeans' Gui builder, Matisse, works off a .form xml file located adjacent to the source file. Matisse creates and maintains the .form file and the code generator creates/updates methods in the java source to reflect changes to the form.

Unfortunately, there is no support in NetBeans for free-form GUI construction.

The closest I've seen is FormGenerator. It's a contributed NetBeans module that adds a right click action to .java files that will attempt to generate a .form file from the .java source. It's very limited, but it's better than nothing. It works best if you've followed the coding style employed by Matisse.

http://netbeans.org/projects/contrib/downloads/download/Readme.txt http://netbeans.org/projects/contrib/downloads/download/FormGeneratorModule.zip


To add a class to the Palette, all that's needed is for your class to conform to the Java Beans model. That is, your class must:

  • be serializable
  • have a public, no-argument constructor.

All fields that have getter and setter methods that are named properly, i.e.:

int count
int getCount()
void setCount(int c)

should by default be recognized as a property.

For a finer control of what properties should and should not be exposed to the GUI Builder, you can associate your class with an implementation of the BeanInfo interface. See this Sun tutorial for more details.

However, NetBeans has several tools to help you in designing a custom bean. You can create new beans using the built-in templates available in the new file dialog, under the "JavaBeans Objects" folder. This tutorial will guide you through creating an Image Bean.

What you could do is create one from scratch, design it as you wish, and then look at the generated code to understand how you can modify your existing class.


Try to use properties (Java bean!) for properties which should be changed from the ui designer and look here for more info.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜