Bind JList When a JCombobox Option Is Changed

Swing Designer allows you to quickly create the frames, panels, dialogs, applets and other UI elements that comprise Java Swing applications.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Bind JList When a JCombobox Option Is Changed

Postby zepernick » Fri Jan 14, 2011 6:06 am

Hello,

I am new to Swing and to WindowBuilder Pro. I am a java dev, but really only develop web apps. I apologize in advance for the noobish questions.

We have a list of Hibernate objects that we have used to populate our JComboBox. Each object in the combobox contains a list that we would like to use to populate the JList when the combo box changes. We were trying various things in the bindings to make this happen, but have not been successful so far.

Are we able to accomplish this using the bindings, or do we need to setup an ActionListener and do something from there?

Thanks,

Paul
zepernick
 
Posts: 2
Joined: Fri Jan 14, 2011 5:56 am

Re: Bind JList When a JCombobox Option Is Changed

Postby Eric Clayberg » Sat Jan 15, 2011 10:13 pm

I have no idea. Are you able to write the necessary Swing Data Binding code by hand to do what you want?
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: Bind JList When a JCombobox Option Is Changed

Postby zepernick » Mon Jan 17, 2011 5:15 am

Eric,

We ended up coding it by hand and it seems to be working.

Code: Select all
comboBox.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent actionevent) {
            if (actionevent.getActionCommand().equals("comboBoxChanged")) {
               final Selection selection = (Selection)comboBox.getSelectedItem();
               if (selection != null && selection.getClaimselecteds() != null) {
                  listModel.removeAllElements();
                  for (Claimselected cs : selection.getClaimselecteds()) {
                     listModel.addElement(cs);
                  }
               }
            }
         }
      });



Thanks,

Paul
zepernick
 
Posts: 2
Joined: Fri Jan 14, 2011 5:56 am

Re: Bind JList When a JCombobox Option Is Changed

Postby Eric Clayberg » Wed Jan 19, 2011 5:31 am

Good. I'm glad that worked. I was not able to find a way to do this using just the Swing Data Binding API, so using a listener was probably the best way to go.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to Swing Designer

Who is online

Users browsing this forum: No registered users and 1 guest

cron