This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JComboBox  RSS feed

 
Tapan Maru
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!