shree
shree

Reputation: 2757

How to set empty string in JComboBox even if data available?

I have a combo box. The values are populating in combo box from DB. But I want to display empty.

Only when I selecting, it should be displayed in the drop down.

Example:

Select Item:   
""
Book
Library
Notebook
Computer

Here Book, Library will come from database. But I need to display first time empty string. I have tried:

combo.setSelectedItem("");

But it's always displaying "Book" only.

How would I do this?

Upvotes: 0

Views: 3700

Answers (1)

JTeagle
JTeagle

Reputation: 2196

Try

setSelectedIndex(-1)

That should do it.

Upvotes: 2

Related Questions