I have created a simple JavaBean and its associated BeanInfo class. When their source files are contained in the same package, the icon provided by the BeanInfo class appears in the NetBeans palette after I add the JavaBean to the palette. I would like to locate the BeanInfo class in another package. When I do this, however, NetBeans can't seem to find it. The javadoc on the Introspector class says there is a BeanInfo search path that starts in the same package, but looks to sun.beans.infos when that fails. I've confirmed that's where the Introspector is looking with this bit:
Which gives me this:
"Core Java" simply says, "The bean info class must be part of the same package as the bean itself." If true, then I'm stuck. But that's not what the javadoc seems to suggest.
Where else can I put my BeanInfo class, other than the same package that contains the JavaBean itself, and still have NetBeans find it?
I've never done anything like this myself before but the Javadocs do say "We first look for the BeanInfo class by taking the full package-qualified name of the target bean class and appending "BeanInfo" to form a new class name. If this fails, then we take the final classname component of this name, and look for that class in each of the packages specified in the BeanInfo package search path." so I would say it is possible provided NetBeans has a way to set the BeanInfo package search path.
You may get better help on this in the IDE forum so I will move the thread there.
Thanks for moving this to a more appropriate forum, Tony. I didn't know this one was here, but I will visit often from now on.
Your reading of the javadoc matches mine. But I've tried every interpretation of what it says that I can, and none of them work. I've tried Googling "netbeans beaninfo search path" and can't find anything that works that way, either. It does work beautifully if I use the NetBeans BeanInfo Editor and leave the <classname>BeanInfo.java file in the package with <classname>.java. It just seems like that creates clutter I'd rather not have, and that the javadoc clearly suggests isn't necessary.
If anyone else has an example or guidance on where else to put the BeanInfo classes, I'd be grateful if they'd share it.
I've found a partial work-around. Adding this code to my JavaBean's nullary constructor and compiling it and the BeanInfo class into the project's jar file lets the IDE find the BeanInfo class in another package:
It's not a good fix, though, because the BeanInfo Editor's Designer can no longer find the original class definition.
subject: Package Options in NetBeans for BeanInfo Classes