classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

javax.swing.JComboBox


From: Chris Lansdown
Subject: javax.swing.JComboBox
Date: Wed, 28 Dec 2005 21:05:02 -0500
User-agent: Mutt/1.5.9i

Hi,

in javax.swing.JComboBox.contentsChanged:

  {
    // if first and last index of the given ListDataEvent are both -1,
    // then it indicates that selected item in the combo box data model
    // have changed. 
    if (event.getIndex0() == -1 && event.getIndex1() == -1)
      selectedItemChanged();
  }

it handles when the indexes are both -1, but it doesn't seem to handle any
other case. Is this indeed the correct behavior? In particular, this seems
to break MetalFileChooserUI, because
DirectoryComboBoxModel.setSelectedItem() always calls fireContentsChanged
as 

  fireContentsChanged(this, 0, items.size() - 1);

So, basically, when the popup list calls JComboBox.setSelectedIndex(...),
JComboBox never calls selectedItemChanged(), which never lets the listeners
in MetalFileChooserUI know that the selected item has changed.

Does this seem right?

DefaultComboBoxModel.setSelectedItem(...) is:

  {
    if (selectedItem == null)
      {
        if (object == null)
          return;
      }
    else
      {
        if (selectedItem.equals(object))
          return;
      }
    selectedItem = object;
    fireContentsChanged(this, -1, -1);    
  }

which is why anything which uses the default model works.

Incidentally, if you modify contentsChanged to run selectedItemChanged() on
other than -1, -1, you seem to get an infinite loop. I think that this is
fixable, however, if you put checks into MetalFileChooserUI's
DirectoryComboBoxAction.actionPerformed to only change the directory and
rescan if something has actually changed. I haven't verified this yet,
though.

Thanks,
-Chris

-- 
"Let us endeavor so to live that when we come to die even the undertaker 
will be sorry."  -- Mark Twain, "Pudd'nhead Wilson's Calendar"
========== Evil Overlord Quote of the Day (www.eviloverlord.com) =========
217. If I'm wearing the key to the hero's shackles around my neck and his
former girlfriend now volunteers to become my mistress and we are all
alone in my bedchamber on my bed and she offers me a goblet of wine, I
will politely decline the offer. 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]