BeanPeeler Demo

This applet is a demo of BeanPeeler v1.3.

If you're writing an app with lots of options and would like to create an edit dialog to allow the user to change them then BeanPeeler could be for you. It allows your app to display such a dialog without going to the trouble of writing it yourself.

BeanPeeler is a property sheet allowing you to customize javabeans. It's similar to the property sheets that you get in IDEs such as Netbeans' Forte that you use to customise components when you drop them onto a form. It examines a bean for any read/write properties and constructs a property sheet using dropdown boxes for properties such as booleans which have discrete values and textboxes for strings and numbers.

Why is this useful? Well, if you are writing a program that has many options then it saves you having to write your own editor dialog. Simply expose the properties you want to edit in the usual javabeans way: write getXXX() and setXXX() methods for them. You can have more control over which ones appear in the dialog by using a BeanInfo class. In the example below I've subclassed a Label and just exposed the methods for setting the text string, colours and font. Clicking on the button invokes

new BeanPeeler(myLabel).show()

which pops up the dialog to allow you to edit the properties.

In this demo it also pops up another BeanPeeler to edit the properties of the first - just to show its versatility. [Note for Netscape users - this second dialog may not display any properties for you. This is due to Netscape being a little more security conscious than IE and requiring an explicit BeanProperty class for the bean you're introspecting. I haven't included one for the BeanPeeler class to keep the download small.]

You can see BeanPeelers used for real in this N-body simulation applet: JOrrery

Note that the appearance of the sheet for editing a particular property (e.g. whether it's a textbox or a drop down) depends on the PropertyEditors that are registered in the JVM you are using. Hence you may find that colours are editable either as textstrings of the form R,G,B or you get a list of colours in a drop down. If the JVM happens to have a custom editor for a colour then you may be lucky and get a nice palette instead.

Click here to download the code and documentation.

Revision History

1.328/11/2001Tidied a lot of the code up. Made the Beanpeeler a PropertyChangeListener, so it can respond to any changes in the underlying bean. [try opening two beanpeelers at once to see how changes in one are reflected in changes in the other]. Also added an option to parse the bean's property names into something more pleasing to the eye.
1.1.11/3/2001Changed the demo to bring up two BeanPeelers, one to edit the first. Added an apply button. Added an option to send the exception stack trace to STDOUT
1.128/2/2001Added the capability to use custom property editors where available
1.020/2/2001Initial release
1