Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

BeanInfo - HORIZONTAL and VERTICAL instead of 0 and 1

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
* enum: VERTICAL MyClass.VERTICAL
* HORIZONTAL MyClass.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?

Thanks
[ June 22, 2007: Message edited by: Jonathan Janisch ]
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
reply
    Bookmark Topic Watch Topic
  • New Topic