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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:38:46+00:00 2026-06-13T17:38:46+00:00

In my application I have 3 combo-boxes, each containing the same list of items,

  • 0

In my application I have 3 combo-boxes, each containing the same list of items, however each can have a different item selected. There is also a button that allows a new item to be added, when it is added it should be added to all three comboboxes, this newly added item should also become the selected item for combox 3, but the items selected for combobox 1 and 2 should not change.

I’m trying to decide whether all three combo-boxes should share the same DefaultComboBoxModel. This would make it easy for the newly added item to appear in each combo, but unlike JList there is not a separate list selection model which would seem to scupper it.

However Javadocs for JComboBoxModel says:

The selected item may not necessarily be managed by the underlying
ListModel. This disjoint behavior allows for the temporary storage and
retrieval of a selected item in the model.

So does that mean I can use a different mechanism for the selected item, I’m unclear on what the above sentence mean.

  • 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-06-13T17:38:47+00:00Added an answer on June 13, 2026 at 5:38 pm

    The only methods that the JComoboBoxModel introduces is getSelectedItem() and setSelectedItem(Object anItem), so I would say no.

    Basically, you could place the data for each model into a single, shared list. You could then create three new instances of a combo box model (either using your own implementation or seeding a DefaultComboBoxModel) that uses this data list. These would then be applied to each combo box separately, so that each combo box had it’s own model.

    List sharedData = //... Create a list of data...
    JComboBox box1 = new JComboBox(new MyComboBoxModel(list));
    JComboBox box2 = new JComboBox(new MyComboBoxModel(list));
    JComboBox box3 = new JComboBox(new MyComboBoxModel(list));
    

    MyComboBoxModel

    public class MyComboBoxModel extends AbstractListModel implements ComboBoxModel {
    
        private List data;
        private Object selectedItem;
        public MyComboBoxModel(List dat) {
            this.data = data;
        }
    
        @Override
        public int getSize() {
            return data.size();
        }
    
        @Override
        public Object getElementAt(int index) {
            return data.get(index);
        }
    
        @Override
        public void setSelectedItem(Object anItem) {
            selectedItem = anItem;
        }
    
        @Override
        public Object getSelectedItem() {
            return selectedItem;
        }
    
    }
    

    You can just as easily use an array if that’s what you’ve got

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using windows application and I have four combo boxes(comboeventname,combosendtype,comboType,comboschedule) in that form....
I have an application which is using a set of three combo boxes. I
I have a combo box on an MVC3 application. When a new item is
I have a wpf application which has combo box and multiple text boxes. On
In my application I have a modal dialog which contains about 20 different combo
I am making desktop application. So, I have to apply checks on combo boxes
I have a combo box in a C# Windows form application that is being
I'm using multiple threads in my application. Basically I have a combo box and
In My application have time consuming process.There fore i try to do that operation
Windows Forms application (c#). I have two ComboBoxes. If I select an item in

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.