954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Clearing a combobox upon selection/focus

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!

stharmon
Newbie Poster
8 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

It looks like I figured this out myself. To clear the selection on a combobox, use "setSelectedIndex(-1);"

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!

stharmon
Newbie Poster
8 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You