| | |
Clearing a combobox upon selection/focus
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Nov 2004
Posts: 8
Reputation:
Solved Threads: 0
Hey all,
I have a simple one I hope. I have created an editable combobox and wanted to clear what is currently displayed in the box once the user sets focus on it either through "tab" or a "mouse click". For example, the combobox would say "Enter a phone number or select your from a list". When the user puts focus on the combobox I want the above string cleared.
So far I have setup the following event.
private void clearPhoneUponFocus(java.awt.event.FocusEvent evt) {
jComboBox1.setModel();
}
I thought I might have to use the setModel method, but can't seem to figure it out. Am I going down the right path? Does anyone have experience doing this and mind lending a hand?
Thanks!
I have a simple one I hope. I have created an editable combobox and wanted to clear what is currently displayed in the box once the user sets focus on it either through "tab" or a "mouse click". For example, the combobox would say "Enter a phone number or select your from a list". When the user puts focus on the combobox I want the above string cleared.
So far I have setup the following event.
private void clearPhoneUponFocus(java.awt.event.FocusEvent evt) {
jComboBox1.setModel();
}
I thought I might have to use the setModel method, but can't seem to figure it out. Am I going down the right path? Does anyone have experience doing this and mind lending a hand?
Thanks!
•
•
Join Date: Nov 2004
Posts: 8
Reputation:
Solved Threads: 0
It looks like I figured this out myself. To clear the selection on a combobox, use "setSelectedIndex(-1);"
•
•
•
•
Originally Posted by stharmon
Hey all,
I have a simple one I hope. I have created an editable combobox and wanted to clear what is currently displayed in the box once the user sets focus on it either through "tab" or a "mouse click". For example, the combobox would say "Enter a phone number or select your from a list". When the user puts focus on the combobox I want the above string cleared.
So far I have setup the following event.
private void clearPhoneUponFocus(java.awt.event.FocusEvent evt) {
jComboBox1.setModel();
}
I thought I might have to use the setModel method, but can't seem to figure it out. Am I going down the right path? Does anyone have experience doing this and mind lending a hand?
Thanks!
![]() |
Similar Threads
- Shortcuts (Windows tips 'n' tweaks)
- combobox - remember last selection (VB.NET)
- Using combobox selection to search dataset (VB.NET)
- Help with a reservation program! GUI Messed XD (Java)
- combo box help (VB.NET)
Other Threads in the Java Forum
- Previous Thread: Wat is method compareTo?
- Next Thread: help needed
Views: 3936 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Java
911 addressbook android api append apple applet application arguments array arrays automation binary bluetooth character chat class classes client code component csv database draw eclipse error event exception file fractal ftp game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me japplet java javaarraylist javaprojects jmf jni jpanel julia linked linux list loop map method methods mobile netbeans newbie number object objects oracle oriented panel print printf problem program programming project projects recursion replaydirector reporting researchinmotion return robot rotatetext scanner score screen se server set size sms socket sort sql stream string swing test threads time tree ubuntu windows





