2

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?

Rob Oxspring
  • 2,835
  • 1
  • 22
  • 28
  • see: http://stackoverflow.com/questions/816286/how-to-include-custom-panel-with-netbeans-gui-builder – will Jan 13 '17 at 03:30

3 Answers3

3

I made JPanel component in NetBeans with overridden paint method:

@Override
public void paint(Graphics g) {
    super.paint(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.

Chobicus
  • 2,024
  • 2
  • 17
  • 26
0

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.

Andy Dingfelder
  • 2,090
  • 2
  • 18
  • 30
0

http://www.netbeans.org search for Matisse.

Rastislav Komara
  • 1,711
  • 8
  • 17