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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:03:36+00:00 2026-05-14T02:03:36+00:00

First, i’m new at Java-programming and my native lang is not english, but still

  • 0

First, i’m new at Java-programming and my native lang is not english, but still i hope to get some help from you all. What I try to do is a simple java-interface with a jComboBox and a jList. I want to poplate to jComboBox with Object-names and when the user select one of the names get the object-id which i will use to populate the jList. It’s probably simple but i have bin stuck with this problem all day.

private void loadComboBox() {
        biz.Object object = new biz.Object();
        try {
            ArrayList<biz.Object> arrayOfObjects= object.getAllObjects();// ArrayList of objects
            for (biz.Object o:arrayOfObjects)
            {
                 if (o != null)
                     cbm.addElement(o); //`toString-method


            }
 cb.setModel(cbm); //JComboBox  
  • 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-14T02:03:37+00:00Added an answer on May 14, 2026 at 2:03 am

    I’m not 100% sure whether I understand your question — but it may well be that you don’t even need to implement your own CellRenderer. Perhaps the following code is helpful to you?

    import java.awt.*;
    import java.awt.event.*;
    
    import javax.swing.*;
    
    public class Test extends JPanel implements ItemListener {
        private JComboBox comboBox;
        private JList list;
    
        public Test() {
            comboBox = new JComboBox();
            list = new JList(new DefaultListModel());
    
            /* initialize combo box */
            loadComboBox();
    
            /* listen for combo box selections */
            comboBox.addItemListener(this);
    
            /* simple layout */
            setLayout(new BorderLayout());
            add(comboBox, BorderLayout.NORTH);
            add(new JScrollPane(list), BorderLayout.CENTER);
        }
    
        /**
         * Invoked when an item has been selected or deselected by the user.
         */
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                /* add item to list */
                ((DefaultListModel) list.getModel()).addElement(e.getItem());
            }
        }
    
        private void loadComboBox() {
            /* let's fake some content here */
            Object[] objects = { "foo", "bar", "baz", "qux",
                                 "quux", "corge", "grault",
                                 "garply", "waldo", "fred",
                                 "plugh", "xyzzy", "thud" };
    
            /* put the objects into the combo box */
            comboBox.setModel(new DefaultComboBoxModel(objects));
        }
    
        public static void main(String[] args) {
            Test test = new Test();
    
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(test);
    
            frame.setSize(300, 400);
    
            frame.setVisible(true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First sorry for my english. I am currently trying to develop a JAVA webservice
first question asked, so I'll get straight to it. I've got some C code
First off, I'm pretty new so I hope I hadn't missed anything too trivial.
First of all, some background: I'm trying to get in a list of integers
First of all, I know how to build a Java application. But I have
first time poster, new to Android programming. Using Eclipse classic, have android SDK loaded
First, I apologize. I know what I want to do, but not what I
first of all some details: I configured security as below in web.xml view plaincopy
first off I'm a noob to PHP but here is my problem. I am
First off, I'm coming (back) to Java from C#, so apologies if my terminology

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.