Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 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
        }
});
However, when some other code updates the items list in cboPlayerList getPlayersYears() gets called, even though no user interaction has taken place on the PlayerList combobox! What am I misunderstanding or what have I misread?

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
cartmen34 is offline  
Old 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...
Rawb is offline  
Old 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
cartmen34 is offline  
Old 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
cartmen34 is offline  
 

Tags
actionevent, confusion, java


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 07:01 PM.

Tilted Forum Project

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62