Beans Binding for Dummies

If you want to really understand "beans binding", i.e., JSR-295, you can study lots of documents. Alternatively, you can go through a small but very powerful demo, here. At the end, you have a bean, which has properties that you bind to Swing components. No coding at all, because the NetBeans tooling makes it a point-and-click experience.

At the end, and only a few clicks later, I moved the demo to the NetBeans Platform, installing it in the IDE's "output" window position. (I created a suite, which included two library wrappers, for the beans binding JAR and the original app JAR, together with my functionality module that provides the TopComponent, which creates the new window in the IDE.) Now, I can change the text in the JTextField below and then immediately the text in the ticker is changed. Why? Because the relevant property in the ticker bean is bound to the Swing component (in real life, when you run the app, the yellow banner with the blue text is moving from right to left, like a "ticker", such as is found on the bottom of the screen on CNN, for example):

Take my advice and follow the Ticker Demo and you too will find out what it's all about.



I would just like to know if there is a demo or tutorial on how to use binding with List and JTable.

- Mark

Posted by Mark Ashworth on February 10, 2008 at 03:18 PM PST #

Hi Mark, see here:

Posted by Geertjan on February 10, 2008 at 04:07 PM PST #

Good Day,

Thank you for your link. I should have specified my needs a bit better.

I have a List to JTable binding but I want to implement the following features:

1. A button that adds an element to the List which should cause the JTable to show a new row but I am not sure of the property change event that I should raise on the listeners for this to work.

2. When I select a row in the JTable I need some property on the form to get that a row was selected. The link above mentions that it is possible but does not describe how.

Another off the beat question is why the following binding does not work:-

Source: Form
EL: ${company.address}

but if I create a bean on the form for the Company class called company1 and I change the init code as follows:

Company company1 = new Company(); //Can't change
company1 = getCompany(); //Pre-init

Source: company1
El: ${address}

then it works. It should evaluate to the same thing. Also not sure why the construction of the company1 variable does not allow me to use the getComapny() method to initialise it.

Mark P Ashworth

Posted by Mark Ashworth on February 11, 2008 at 06:34 AM PST #

Mark, I think the next blog entry, called "Beans Binding Via the Road Less Travelled By", answers several of your questions. If not, please feel free to ask again.

Posted by Geertjan on February 11, 2008 at 07:15 AM PST #


Thank you for the road less travelled tutorial.

For beans binding to see that an object was added to a List<Department> I found that the following worked but I am not to sure if it is optimal.

public void setDepartments(List<Department> departments) {
List<Department> old = getDepartments();
this.departments = departments;
firePropertyChange("departments", old, getDepartments());
public boolean add(Department department) {
List<Department> d = new ArrayList<Department>(getDepartments());
boolean result = d.add(department);
return result;

Posted by Mark Ashworth on February 11, 2008 at 08:40 AM PST #

Hi Mark, does the next part in the series help you?

Posted by Geertjan on February 12, 2008 at 01:21 AM PST #

Hi, thanks for the demo! It was very helpful and interesting although it's small.

Posted by Pixy on February 12, 2008 at 09:35 PM PST #

Have you ever created a mobile game in netbeans before? could give us a complete sample including source codes,plug-ins,sprites and etc...

Posted by Celal Krutz on February 13, 2008 at 10:07 AM PST #

Hi Geertjan,

Nice blog entry.

You may be interested in a new Open Source project I've just released which helps automate the use of Beans Binding:

If you have the time, your feedback would be very helpful to me.



Posted by Richard Kennard on February 13, 2008 at 01:35 PM PST #

I would like to see more examples of binding a pojo-sytle model to a swing view via beans-binding jsr 295 (as this is by far the major use-case of beans binding).

Posted by Allen Parslow on March 26, 2008 at 11:14 PM PDT #

@Allen Parslow:

The ClassBuilder project use annotations and code injection to extend pojos with cumbersome fire\*-methods. It's a small project, functional, but in alpha stage.

best regards, josh.

Posted by Aljoscha Rittner on January 24, 2009 at 04:32 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« July 2016