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 5844293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:16:20+00:00 2026-05-22T12:16:20+00:00

I have a table in database employee composed by two columns ID and NameLastName

  • 0

I have a table in database employee composed by two columns ID and NameLastName.

I arrived to add data in the second column to a JComboBox like in the snapshot down!

enter image description here

Now how can I do to delete the selected employee in the JComboBox from DB?

I thought to add the ID with name like this I122-Name and use split method to extract the ID but I don’t want to show the ID.

Is there any way to associate with each name in the JComboBox a hidden value that contains the employee ID?

  • 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-22T12:16:20+00:00Added an answer on May 22, 2026 at 12:16 pm

    I don’t want to show the ID.

    This question has already received 2 good answers, but I wanted to add this 3rd one if only to address the question of whether to show the ID (which was not part of the question, but should have been).

    Screen Shot

    Which John Smith are you going to fire?

    enter image description here

    SackEmployee.java

    import java.awt.*;
    import javax.swing.*;
    
    class SackEmployee {
        public static void main(String[] args) {
            SwingUtilities.invokeLater( new Runnable() {
                public void run() {
                    Employee[] workforce = {
                        new Employee("Ali Ben Messaoud", 9823),
                        new Employee("Jane Brewer", 6348),
                        new Employee("John Smith", 1247),
                        new Employee("John Smith", 4385)
                    };
    
                    JComboBox employeeCombo = new JComboBox(workforce);
    
                    EmployeeCellRenderer employeeCellRenderer = new EmployeeCellRenderer();
                    employeeCombo.setRenderer(employeeCellRenderer);
    
                    int result = JOptionPane.showConfirmDialog(
                        null,
                        employeeCombo,
                        "Fire Employee?",
                        JOptionPane.OK_CANCEL_OPTION);
                    // cast selected item back to Employee.
                    Employee employee = (Employee)employeeCombo.getSelectedItem();
                    System.out.println( "Fire '" + employee + "' now?" );
                    System.out.println( "Proceed: " + (result==JOptionPane.OK_OPTION) );
                }
            });
        }
    }
    
    class Employee {
    
        int id;
        String name;
    
        Employee(String name, int id) {
            this.id = id;
            this.name = name;
        }
    
        public String getIdString() {
            return "ID-" + id;
        }
    
        public String toString() {
            return getIdString() + ": " + name;
        }
    }
    
    class EmployeeCellRenderer implements ListCellRenderer {
    
        JLabel label = new JLabel();
    
        public Component getListCellRendererComponent(
            JList list,
            Object value,
            int index,
            boolean isSelected,
            boolean cellHasFocus) {
    
            Employee employee = (Employee)value;
            // distinguish between people of same name by adding ID.
            label.setText(employee.name + " (" + employee.getIdString() + ")");
    
            return label;
        }
    }
    

    E.G. I/O

    prompt>java SackEmployee
    Fire 'ID-9823: Ali Ben Messaoud' now?
    Proceed: false
    
    prompt>java SackEmployee
    Fire 'ID-1247: John Smith' now?
    Proceed: true
    
    prompt>java SackEmployee
    Fire 'ID-4385: John Smith' now?
    Proceed: false
    
    prompt>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table in my database with 2 rows of employee data. ...........
I have two tables in my database: Company table (ID, CompanyName, CompanyUsername, CompanyPassword) Employee
I have ten fields in my table in database..And two columns out of them
I have two tables in my database as following: Employee Table: Username, Name, Job,
i have database table like this +-------+--------------+----------+ | id | ip | date |
I have a database table named call with columns call_time, location, emergency_type and there
How should columns in a database table that have a PK/FK relationship be named?
I have an EMPLOYEE table in a SQL Server 2008 database which stores information
As I am working on Employee Management system, I have two table (for example)
I have an employee table which contains a manager ID as a column. If

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.