Originally posted by thejaswini ramesh:
But the problem is in the actionPerformed,2 events are firing when you press enter - 'comboBoxEdited' and 'comboBoxChanged' and 3 evnts for the go button('go' along with 'comboBoxEdited' and 'comboBoxChanged').Now suppose i print the typed text(am supposed to display in a textarea),then the same text is displayed twice or thrice...this is whats causing me the problem as am supposed to display the text once whether i press enter key or click the go button.Can you suggest a way to work around this??
Hmmm... I didn't realize this your original question...
As a matter of GUI design, the JButton may be viewed as redundant, because action events are fired when you make a selection, even if it is the same as the current selection, or if you press VK_ENTER when focus is on the JComboBox. So it is up to you to decide if you want to include the JButton -- many users may prefer to use it.
If reacting to *all* the action events causes you to react multiple times to the same selection, ask youself how you would want your GUI to react if the user keeps clicking on the JButton. Do you react to each event or ignore the latter clicks? Do ever react by clearing the selection?
As for the muliple events generated by typing into the JComboBox followed by VK_ENTER, note the ActionEvent's actionCommand: it will be "comboBoxChanged" versus "comboBoxEdited" (versus the button's label when the button is clicked). Thus your listener can distinquish between these types of events and react as you dictate.