views:

124

answers:

1

Hello,

I would like to know the best method of breaking up large Java Swing classes. Some of mine are quite large and I would like to begin the process of properly modularizing my code. I saw that I could add my classes to Netbeans' palette but the problem is they are not showing me a graphical representation of what it will look like when I "drop" them into the GUI designer. Some third party jar files support getting added to the palette and they provide a graphical preview of what they'll look like once run.

My question is, I don't know the proper terminology for what this "preview" is called so I'm finding it very difficult to search for. I would like some documentation or a tutorial on how to make my current classes able to be added to the palette and see what it is they will look like in the GUI designer.

Thank you!

+3  A: 

To get an icon, you need to provide a BeanInfo for you class.

The easiest way to do this is right click on the class in the Project window and select BeanInfo editor....

You'll want to switch to the designer view to configure which properties are expert/hidden/preferred.

  • Preferred properties appear in the top most fold (Properties) of the Property window.
  • Expert properties appear in the second fold (Other Properties).
  • Hidden do not appear at all.

You can also specify whether properties are bound, constrained, etc. To set icons, choose the topmost node of the tree (BeanInfo) and you'll see properties for the icons.

To make NetBeans treat your component as a container (or not a container):

  • Switch to Source view
  • Find the line reading
    // Here you can add code for customizing the BeanDescriptor.
  • Add this line:
    beanDescriptor.setValue("isContainer", Boolean.TRUE); // Or FALSE if it's not a container
Devon_C_Miller
Thank you - however when you say icon, do you mean one of those 32x32 icons that display on the palette? Or the actual image that comes up when placed in the editor. I am interested in the image that comes up in the editor.
Ryan
The icon is displayed in the palette. The presentation in the editor is a result of how your component paints itself. If you need to perform different painting during editing, you can do that by checking the value of java.beans.Beans.isDesignTime().
Devon_C_Miller
I understand that is where the check is to see if it is being edited, but where do I provide the specifics to how it's rendered in the gui designer? I have been looking at bean javadocs but haven't had much luck.
Ryan
What is displayed in the editor is what the component's paint code (paintComponent,paintBorder, paintChildren, etc) is rendering, given the default state provided by the zero-argument constructor.
Devon_C_Miller