Announcement Announcement Module
Collapse
No announcement yet.
Binding to ComboBox Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Do your Garage objects provide an implementation for equals?

    Comment


    • #3
      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?

      Comment


      • #4
        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

        Comment


        • #5
          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.

          Comment

          Working...
          X