How to set a Java bean property as an expert property?
The Java Beans Introspection API includes in the PropertyDescriptor
class the method isExper开发者_Go百科t
. Bean-based GUI editors, like WindowsMaker, use this to hide or show "exotic" properties.
What causes a certain property of a Java bean to be considered "expert"? How does the Swing library, for example, sets certain properties as "expert properties"? How can I programmatically do the same for Java beans that I write?
This apparently is done in the JDK using a non-standard compiler extension.
If you have a look at the Swing source code, some Javadoc comments include a @beaninfo
tag, containing such information:
/**
* ... Some comment ...
* @beaninfo
* bound: true
* expert: true
*/
public void setSomething(SomeType value) {
// ...
}
Here is an example, in the JTable class source code.
I also found this article, talking about the @beaninfo
tag.
You can create a BeanInfo class for your bean. This allows you to customize the property descriptor. There is a section covering this in the JavaBean tutorial.
精彩评论