How do I create a custom JPanel extension and use it from the NetBeans palette?

I have a JPanel extension that I've written and would like to be able to use it in the NetBeans designer. The component is simply adds some custom painting and continues to function as a container to be customised on each use.

I have properties to expose in addition to the standard JPanel ones and have a custom paintComponent() method that I'd like to be able to see in use when building up GUIs. Ideally I'd like to associate an icon with the component as well so that its easily recognisable for my colleagues to work with.

What's the best way of achieving this?

Asked by: Dominik358 | Posted: 28-01-2022

Answer 1

I made JPanel component in NetBeans with overridden paint method:

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    //draw elements      

It has some custom properties accessible through NetBeans properties window.

public int getResolutionX() {
    return resolutionX;

public void setResolutionX(int resolutionX) {
    this.resolutionX = resolutionX;

public int getResolutionY() {
    return resolutionY;

public void setResolutionY(int resolutionY) {
    this.resolutionY = resolutionY;

I put it in my palette using: Tools->Palette->Swing/AWT Components.

It even has the same look I painted in my overridden paint method while I am doing drag/drop in another container. I didn't associate icon to it though.

Hope this helps.

Answered by: Fenton431 | Posted: 01-03-2022

Answer 2 search for Matisse.

Answered by: Miranda602 | Posted: 01-03-2022

Answer 3

You can add your custom component to the matisse GUI palatte.

  1. Build your project so the class file you want to use is part of the jar file
  2. Open a java class that has a form, and switch to design mode. 3, Right click in the palatte and choose "palatte manager".
  3. Choose the "add from jar" button to select your jar.
  4. 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.

Answered by: David588 | Posted: 01-03-2022

Similar questions

java - How to add file extension in netbeans?

I have integrated the JasperReports library in Netbeans 7.0.1 by using Library Manager wizard. now i want to define a template file extension .jrxml .In a tutorial i read that this can be done by Advanced options that is under tools>options dialogbox.but in ide 7.0.1, their is no advanced options in options dialog box.can any one help?

java - Netbeans Platform Getting File Path in Editor's Action Extension

I've created an Action To HTML Editor and Added it to its Menu Context following the tutorial here and now I have the following: public final class PreviewAction implements ActionListener { private final EditorCookie context; public PreviewAction(EditorCookie context) { this.context = context; } @Override ...

Java file extension regex

I'm trying to come up with a Java regex that will match a filename only if it has a valid extension. For example it should match "" and "foo.b", but neither "foo." nor "foo". I've written the following test program public static void main(String[] args) { Pattern fileExtensionPattern = Pattern.compile("\\.\\w+\\z"); boolean one = fileExtensionPattern.matcher("").matches(); boole...

Java sort String array of file names by their extension

I have an array of filenames and need to sort that array by the extensions of the filename. Is there an easy way to do this?

java - How to hide the .jsp extension in my web server urls

I have a JSP web server, with pages that all end with the .jsp extension. How can I hide it in my web server urls without resorting to non-java tricks (e.g., apache rewrite)? For example: instead of typing the user would just type http://www.sam...

java - Howto design for extension

There is a Checkstyle rule DesignForExtension. It says: if you have a public/protected method which is not abstract nor final nor empty it is not "designed for extension". Read the

java - Apache Felix: What are extension bundles?

Apache Felix has the concept of an "extension bundle". This seems to be a bundle that contributes to the system bundle. There is also a special URL "felix://extensions/" being registered for them. When would I need to use extensions as opposed to regular bundles? Are there examples of bundles that use this approach? Is this a Felix-only feature or part of the OSGi spec?

java - How to create a JButton extension with rounded corners?

This is a continuation of the question "Java rounded Swing JButton". I have searched for an extension of javax.swing.JButton which will inherit all runtime behavior and just override drawing of the corners. Using the code given by noah.w on

Need citation for Extension Interface pattern in Java

The following Java design allows an object to be extended without changing its interface to clients. The object can implement additional extension interfaces. Clients can ask the object for extension interfaces that it implements. I read about it in a blog post, but my Google skills failed to find the blog post again. I'm not advocating the merits of this design. I just want to find the blog post. For example,...

java - Adding a template to an extension point in Eclipse

I am a fan of adding extension points to my Eclipse RCP applications, as it makes them very modular. Now, when you write the extension point schema, it is possible to add the documentation that will be shown in the Extension Point Selection wizard. This wizard contains also an Available Templates section. When a template is selected, some code is generated for you. In this case I would like to use some AbstractC...

java - Eclipse extension for opening TIFF (type 4) images?

I need to display a TIFF (type 4) image in Eclipse from a Java stream. TIFFv4 is not supported, so I need an image library. Sun's JAI-ImageIO has native code -- I can't wrap it easily into a plugin. I can't just import jai-imageio.jar (et al) from the lib\ext directory because Eclipse has its own ideas about classpaths. Any suggestions for image extensions / libraries usable in Eclipse? Although I've go...

java - How to open file without extension

I would like to try open file without extension. When I try to open file without extension, then system show me "Open with" form. But when I am trying to open that file in side my application using method: private static void openFile(String fileName) throws IOException { if(Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); File file = new File(fileN...

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)