Netbeans: using GUI Builder on regular Java class file

前端 未结 3 509
梦如初夏
梦如初夏 2021-01-21 06:02

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 ne

3条回答
  •  独厮守ぢ
    2021-01-21 06:29

    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.

提交回复
热议问题