Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Java in General and the fly likes BeanInfo - HORIZONTAL and VERTICAL instead of 0 and 1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "BeanInfo - HORIZONTAL and VERTICAL instead of 0 and 1" Watch "BeanInfo - HORIZONTAL and VERTICAL instead of 0 and 1" New topic

BeanInfo - HORIZONTAL and VERTICAL instead of 0 and 1

Jonathan Janisch

Joined: Mar 17, 2007
Posts: 24
For some reason BeanInfo is one of those things I feel like I'll never learn. I've read through the tutorials on sun's site and countless others and IMHO the examples they provide are either too simple or too complex.

I have a class MyClass and a bean info class MyClassBeanInfo which extends SimpleBeanInfo.

MyClass has one normal javabean property: orientation which has:

int getOrientation() and void setOrientation(int orientation).

1) In the NetBeans properties window, orientation is shown in the "other properties" section. How can I make it a "main property"?

2) Also, if you edit the orientation field you can enter any int value in there (although in my case I'm throwing an IllegalArgumentException so netbeans fails to write an illegal value). With Swing controls like JSlider, the orientation property allows you to select between HORIZONTAL and VERTICAL. It doesn't allow you to enter any int value. I looked at the source for JSlider and it appears to use annotations for beaninfo (is this preferred? all the tutorials appear to be outdated). I copied and pasted the annotation and got rid of my beaninfo class and it still allowed me to enter any integer.

* Set the orientation
* @param orientation the new orientation
* @throws IllegalArgumentException if orientation is not one of {@code VERTICAL}, {@code HORIZONTAL}
* @see #getOrientation
* @beaninfo
* preferred: true
* bound: true
* attribute: visualUpdate true
* description: Set the scrollbars orientation to either VERTICAL or HORIZONTAL.

3) Also, when the orientation property is called, the control should resize itself to the vertical/horizontal preferred size.

Note: I'm using NetBeans 6 M9 and they appeared to remove the bean editor so I have to do it all by hand which I prefer for learning anyway. Is there a really good up to date tutorial on custom java components, beaninfo, etc that does not show up in the top 100 google results?

[ June 22, 2007: Message edited by: Jonathan Janisch ]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15092

Sorry, I don't use NetBeans so I can't answer your NetBeans-specific questions. But I hope this will help:

How about using an enum instead of an int for the return value and argument of your methods? Something like this:

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: BeanInfo - HORIZONTAL and VERTICAL instead of 0 and 1
It's not a secret anymore!