This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes GUI like the Internet Explorer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GUI like the Internet Explorer" Watch "GUI like the Internet Explorer" New topic
Author

GUI like the Internet Explorer

thejaswini ramesh
Ranch Hand

Joined: Oct 19, 2005
Posts: 74
Hi everyone,
I have posted previously about this problem,but I haven't got a solution as yet.I am using swings to create my application which has some feature of the IE that is the editable combobox and a button(in case of IE,the place where you enter the URL and the go button).My application should work like wise...i mean whether user clicks button or presses enter after typing in the combo,a particular task has to be performed.Is this possible in swings??
I have been encountering a number of problems with the editable combobox and the button.I have tried writing action listener as well as key listener for the combo,but i've not been able to do the task.Please can anyone give me an idea if this is possible or not and which listener to use for application to work as described above?
All suggestions are appreciated.

Thejaswini.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
If you can dream it, you can do it! (By the way, its called "Swing", not "swings" -- note the name of this forum, for example. I don't know who started calling it "swings").


There is no emoticon for what I am feeling!
thejaswini ramesh
Ranch Hand

Joined: Oct 19, 2005
Posts: 74
Thanks Jeff.Made note of the fact that its "Swing" and not "Swings"...
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??

Thanks,
Thejaswini.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GUI like the Internet Explorer
 
Similar Threads
Editable combobox events
Question about JCombobox
How to write an event for "Enter" key?
Handling keyboard event in JComboBox without making it editable
Combo box focus problem