views:

63

answers:

1

This might be a stupid question but is it possible for NetBeans IDE to add custom properties to my custom component which I already have placed in the Palette and if so then how? I have been looking all over the internet and haven't found anything that would help me figure it out.

Thanks, Martin S.

+1  A: 

Hi Martin,

Let me state your requirement in my words first.

  1. You need custom swing components in your palette
  2. You need new custom properties to your custom components
  3. You want those new properties to appear in the properties panel so you can set them in design time

The above mentioned things are possible in NetBeans IDE.

NetBeans IDE allows you to add custom components to Palette. You need to follow some rules as follows:

  1. The custom component shall have a no arguments constructor
  2. The custom component shall be in a compiled state, the palette manager uses the class file to add it.
  3. The new properties will be automatically shown in the Properties panel, provided they have valid getter and setter methods according to the Java bean standards.

I have not written the method of adding a custom component to palette as you have already done that as mentioned by you. The NetBeans Palette allows you to create new Palette categories and add new components to the Palette from a JAR file, or a project also if the class is compiled.

with regards
Tushar

enter code here
Tushar Joshi
thank you for your answer, I already sucessfully added my customed JPanel to my category in the Palette. I haven't been able to add custom properties. What are these Java bean standards that need to be followed?
Martin S.
Java Bean standard says that the property shall have a getter and setter. For example if you have a private variable status then you shall have getStatus() and setStatus() methods. I tested this with one custom component which extends JComponent and with one boolean and one String property having proper getter and setter methods. That component showed me those properties in properties panel.
Tushar Joshi
and does it matter how do I call the setter and getter methods or NetBeans detects that the particular method returns the value of the variable and another one sets it no matter how it's called?
Martin S.
If you have methods like setStatus() and getStatus() in your component the Properties Panel will show status as a property. It does not matter or is related with how you call these methods in your code in my opinion.
Tushar Joshi
Thank you very much sir!
Martin S.