20

I have written a class that extends JPanel. Is it possible to use this in the NetBeans GUI Builder and have it survive all of the automatic code generation?

I have used the customised code option in the GUI builder to instantiate the object as the new class, but it seems like the declaration can't be changed from JPanel, so only methods that I have overridden get called, I can't call new ones that are not present in JPanel.

Curyous
  • 8,716
  • 15
  • 58
  • 83

3 Answers3

27

Simply drag the class from the projects tree on to the form in the GUI designer.

Just like it says in stackoverflow question 691890.

Community
  • 1
  • 1
Curyous
  • 8,716
  • 15
  • 58
  • 83
14

You can use the Palette Manager to add your component to the palette, then you can use it in the GUI builder as you would any other class.

At one point this was covered on the NetBeans Wiki, which is now defunct. Now the only official documentation I can find on it is in the new Apache NetBeans knowledge base:

For advanced developers, the Palette Manager is available that enables you to add custom components from JARs, libraries, or other projects to the Palette. To add custom components through the Palette Manager, choose Tools > Palette > Swing/AWT Components.

Michael Myers
  • 188,989
  • 46
  • 291
  • 292
11

Just provide a public no-arg constructor for your class. You can then add the class to the Palette by right clicking on it and selecting Add to Palette.

JRL
  • 76,767
  • 18
  • 98
  • 146