Monday, September 14, 2009

JComboBox pure craziness

Someone asked me why his ItemListener, attached to a JComboBox, was getting two events when he selected something on it. Weird.

I looked up JComboBox' javadocs, just to be sured, and....this is what I found:

Adds an ItemListener.

aListener will receive one or two ItemEvents when the selected item changes.

I understand Swing is a huge framework and it has its rough edges...but this? It certainly looks like someone couldn't fix this strange behavior, and desided to make it a documented feature instead. Way to go!

2 comments:

  1. I could not see the line "Adds an ItemListener.
    aListener will receive one or two ItemEvents when the selected item changes." in the document that you have pointed to.

    ReplyDelete
  2. Hmm. Very strange. These looked like real javadocs, but they seem fake after all. I'm fixing the link to point to Sun's javadocs, thanks.

    ReplyDelete