Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 555283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:47:56+00:00 2026-05-13T11:47:56+00:00

I have a table in a database that contains two fields id name I

  • 0

I have a table in a database that contains two fields

  • id
  • name

I have populated a JComboBox “combo1” with all the names stored in the DB. Now I want that whenever a user selects an item of the “combo1”, I can recognize the “id” of the selected item.

But the problem is that names can be duplicates in a table. So let assume if a table has 3 duplicate names, then

Q1. How to show the items in the “combo1” so that user can distinguish between those common names?

Q2. After the user has clicked an item, How can I recognize that on which item the user has clicked, if the selected item has duplicates?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:47:56+00:00Added an answer on May 13, 2026 at 11:47 am

    use a class to store your pair of data. JComboBox will use its toString() method as the label.

    public class Item
    {
        int id;
        String name;
    
        public String toString()
        {
            return this.name+"("+id+")";
        }
    }
    (...)
    Item array[]=new  Item[]{ ... };//fill the array with your items
    JComboBox c=new  JComboBox(array);
    (...)
    //use the combo
    (...)
    Item selected=(Item)c.getSelectedItem();
    System.err.println("id is "+selected.id);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two simple tables in my database. A card table that contains Id,
I have a database table TravelRequest that contains, amongst other things, the fields SignOffName
I have a database structure that has a Person table which contains fields such
I have a database with a table that contains Name and CompanyName . They
I have a database that contains two fields that collect multiple values. For instance,
I have a table in a sql server 2008 database that contains bunch of
I have a database that contains a table that looks a bit like this:
I'm trying to normalize a mysql database.... I currently have a table that contains
I have a table in database that is having some fields one of which
I have a mysql database that has 2 table. the first table contains the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.