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 JComboBox 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 "JComboBox" Watch "JComboBox" New topic


Tapan Maru
Ranch Hand

Joined: May 08, 2006
Posts: 65
Hello All,

I want to initialize my combobox with objects from my database table.

What I want is combobox should display description of the selected object while it gives me id of that record when I am submitting the window for saving my record.

e.g. I am having five districts in my district_mst table. Pune, Bangalore, Hyderabad, Chennai, Ahmedabad are descriptions stored in desctription column of my database table and corosponding PrimaryKey values are 1,2,3,4,5.

I want to display district names in my JFrame while want to send PK value when I submit the JFrame.

Any suggestions/demo code for this purpose?

Thanks In Advance,

Tapan Maru

Tapan Maru
Rob Spoor

Joined: Oct 27, 2005
Posts: 19655

Store your entire data objects in the model, then either override toString() of the data object class to return the description, or use a ListCellRenderer to display the description.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: JComboBox
Similar Threads
ComboBox Item Display
combining two classes
Display a JFrame, without Applet
ComboBox component (not JComboBox)
ComboBox component (not JComboBox)