• Post Reply Bookmark Topic Watch Topic
  • New Topic

BeanInfo - HORIZONTAL and VERTICAL instead of 0 and 1

Jonathan Janisch
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15711
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!