Thanks, your feedback led me in the right direction and I've got it
working.  I find it strange that when you change the selected item in
a combo box, that you need to create a "contents changed" event.  I
would think some sort of "selection changed" event would be more
appropriate.  I had to override the
ULCComboBox#contentsChanged(ListDataEvent). When it received an event,
it kept telling the DateComboBoxModel to setSelectedItem(null).  I'm
not really sure why.  I've noticed that ULCComboBox(List) doesn't
handle null values in the list as I would expect.  To get around that
I use "" when I'm dealing with String's, but I was dealing with Date's
this time around.  Here are the main code snippets that ended up
working for me:

DateComboBoxModel

 import org.springframework.util.ObjectUtils;

 public void setSelectedItem(Object item) {
   if(!ObjectUtils.nullSafeEquals(_selectedItem, item)){
     _selectedItem = (Date)item;
     ListDataEvent event = new ListDataEvent(this,
ListDataEvent.CONTENTS_CHANGED, -1, -1);
     for(IListDataListener listener : listeners){
       listener.contentsChanged(event);
     }
   }
 }

DateComboBox

 @Override
 public void contentsChanged(ListDataEvent event){}


Thanks,
Cameron



On 5/2/06, Etienne Studer <[EMAIL PROTECTED]> wrote:
Hi Cameron

My guess is that you don't fire an event after setting the selected
element on the combo box model.

Your model should look something like below...

I hope this solves your issue.

Etienne



public class DateComboBoxModel extends AbstractListModel
                               implements IComboBoxModel {
    public Object getSelectedItem() {
        return _selectedItem;
    }

    public void setSelectedItem(Object inItem) {
        selectIfChanged(inItem);
    }

    private void selectIfChanged(Object inItem) {
        if (!ObjectUtils.equals(_selectedItem, inItem)) {
            _selectedItem = inItem;
            fireContentsChanged(this, -1, -1);
        }
    }

    private Object _selectedItem;
}



> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:ulc-developer-
> [EMAIL PROTECTED] On Behalf Of Cameron Taggart
> Sent: Tuesday, May 02, 2006 5:37 PM
> To: [email protected]
> Subject: [ULC-developer] ComboBox List<Date> setSelectedIndex(0)
>
> I created a DateComboBox and DateComboBoxModel which simply display
> List<Date>.  Selecting a date is optional on my form, so the first
> date in the list, I've set to null.  I have a "clear" button on my
> form which needs to reset the ComboBox to the first item.  Right now,
> the model gets changed to the correct value, but the ComboBox in the
> UI does not.  Any idea how I might get the ComboBox selection to
> visually change to the selected item?  Was there an event I was
> supposed to fire off?
>
> Thanks,
> Cameron
> _______________________________________________
> ULC-developer mailing list
> [email protected]
> http://lists.canoo.com/mailman/listinfo/ulc-developer

_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer

Reply via email to