How can I use a custom subclass of a Swing component? Do I need to install it to palette?
-
06-06-2021 - |
Question
How can I add NewJPanel, a Netbeans generated class which extends JPanel, to the palette for the GUI builder?
The goal is to be able to add a NewJPanel through the palette so that it has type NewJPanel rather than type JPanel. However, it's not available through the palette as I would expect.
I'm following:
To install via Palette Manager
Open the Palette Manager from main menu: Tools | Palette Manager | Swing/AWT Components In the Palette Manager press button according to where the component comes from. The choices are: from an external JAR file from a library defined in the IDE (always create a library if the components need more than one JAR) from a NetBeans project
from the Netbeans FAQ's.
This method doesn't work because the classes just aren't available for selection.
However, I was able to drag NewJPane onto the design view of NewJFrame where it was declared with the correct type of NewJPane (and not JPane).
Solution
You can add your custom component to the matisse GUI palatte.
Build your project so the class file you want to use is part of the jar file
Open a java class that has a form, and switch to design mode. 3, Right click in the palatte and choose "palatte manager".
Choose the "add from jar" button to select your jar.
Choose the class you made, and add it to your palatte.
Now your panel is known to netbeans, and you can drag it into new panels.