01-03-2005, 08:43 PM | #1 (permalink) |
Psycho
Location: the hills of aquafina.
|
[Java] ActionEvent confusion
Ok, I'm confused. I'm being told one thing by my book and I'm seeing the exact opposite when I implement the listener. Here's the quote straight from the Swing book I bought:
"Combo boxes fire both and ItemEvent and an ActionEvent when the selection in the list has changed. the ItemEvent is fired when there is a change in the current selection of the list, from any source. the ActionEvent is fired when the user explicitly makes a selection; it is coupled with the actionCommand property." so..... Code:
cboPlayerList.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { getPlayersYears(); //populate the cboPlayersYears combobox } }); Thanks for your help guys!
__________________
"The problem with quick and dirty, as some people have said, is that the dirty remains long after the quick has been forgotten" - Steve McConnell |
01-04-2005, 12:27 AM | #2 (permalink) |
Crazy
Location: Salt Town, UT
|
Now, I'm not a java guy, so I'm coming at this one from right field.
But here is what I am thinking, whenever the list is updated, whatever selection they had before may or may not still be there, or may or not be in the same position, so it probably goes through a section of re-selecting the current selection, which fires off your event. It seems like a pretty reasonable thing to do. Perhaps they selected the "Other..." option, and now you have populated the "Other..." choices some more... |
01-04-2005, 01:18 PM | #3 (permalink) |
Psycho
Location: the hills of aquafina.
|
yes, that is what is happening. My problem is that there is no way to tell if the user is actual selecting an item, or if an item is being updated by code. I've dug into the ActionEvent class and there is nothing to tell them apart.
The action command that is fired is "comboboxchanged". This is what is returned both when the combobox items are updated, and also when the user selects an item from the combobox. No way to tell them apart at all.
__________________
"The problem with quick and dirty, as some people have said, is that the dirty remains long after the quick has been forgotten" - Steve McConnell Last edited by cartmen34; 01-04-2005 at 01:26 PM.. Reason: spelling...it is a biatch |
01-04-2005, 08:43 PM | #4 (permalink) |
Psycho
Location: the hills of aquafina.
|
Ok, I've got it sorted out. I just ran an in statement within the actionEvent that checked for the ItemCount of the combobox. If the itemCount != 0 then do nothing, otherwise getPlayersYears.
so simple. This is an example of why I'll never be a great programmer.
__________________
"The problem with quick and dirty, as some people have said, is that the dirty remains long after the quick has been forgotten" - Steve McConnell |
Tags |
actionevent, confusion, java |
|
|