Results 1 to 5 of 5

Thread: Binding to ComboBox

  1. #1
    Join Date
    Mar 2005
    Posts
    14

    Default Binding to ComboBox

    I would really appreciate some help here. I have been playing with this for days now and it seems like it should be a pretty simple thing to do.

    I have two classes.

    Code:
    public class Garage {
      private String name;
      private Set cars;
    
      // getters / setters omitted
    }
    
    public class Car {
      private String name;
      private String color;
      private Garage garage;
    
      // getters / setters omitted
    }
    I have created a class called CarGeneralForm that extends AbstractForm the createFormControl() looks like:

    Code:
    protected JComponent createFormControl() {
      TableFormBuilder formBuilder = new TableFormBuilder(getFormModel());
    
      JComboBox garageSelector = getFormModel().createBoundComboBox("garage", garageList.toArray());
    
      formBuilder.row();
      formBuilder.add("name"); // text field to accept the name
      formBuilder.row();
      formBuilder.add("color"); // text field to accept the color
      formBuilder.row();
      formBuilder.add("garage", garageSelector); // combo box containing all garages from the database
      return formBuilder.getForm();
    }
    My problem is that when I display this form in a properties window (so that you can edit the car), the garage is not selected in the ComboBox.

    I am at a total loss on what I am doing wrong. I have searched the forums but have not been able to find anything that helps.

    Thank you very much for any assistance that anyone could offer.[/code]

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    335

    Default

    Do your Garage objects provide an implementation for equals?

  3. #3
    Join Date
    Mar 2005
    Posts
    14

    Default

    I just implemented the equals() but that did not do it. I did put some print statements in the equals(), it finds the one that it is equal to, but it is still not displayed in the combo box.

    Any other ideas?

  4. #4
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    335

    Default

    Sounds like a bug. I'd try tracing through the code to see exacactly whats going on. Start be placing a breakpoint in you equals method and see what the binding code does.

    Ollie

  5. #5
    Join Date
    Mar 2005
    Posts
    14

    Default

    Very sorry, I replied to soon. That did work, I just had some other code in there that I had to remove first.

    Thank you very much oliverhutchison! That was very helpful.

Similar Threads

  1. Enum binding not showing default
    By ge0ffrey in forum Swing
    Replies: 3
    Last Post: Jan 23rd, 2006, 09:08 AM
  2. Create binding for existing combobox
    By darabi in forum Swing
    Replies: 1
    Last Post: Oct 7th, 2005, 02:50 PM
  3. Replies: 7
    Last Post: Sep 13th, 2005, 01:45 AM
  4. Replies: 0
    Last Post: Jan 6th, 2005, 08:19 AM
  5. Replies: 2
    Last Post: Aug 17th, 2004, 04:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •