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

  • Home
  • SEARCH
  • 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 7668609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:24:21+00:00 2026-05-31T15:24:21+00:00

I have list of objects(Artikel.java) and i add them to JComboBox. I want a

  • 0

I have list of objects(Artikel.java) and i add them to JComboBox.
I want a property(String name) of this object be in the list? i did as below but stil the object is in the list and it is not readable.

how can i do it? Where is my problem?

if (titel.equalsIgnoreCase("artikel")) {
            panel.lstArtikel = readFromArtikel();
            panel.cbxArtikel = new WebComboBox(new ComboBoxModelArtikel(panel, lstArtikel));
            panel.cbxArtikel.setAction(new ComboBoxArtikelActionListener(panel));
            panel.cbxArtikel.setRenderer(new ArtikelListRenderer());
            panel.artikelTabPanel.add(panel.cbxArtikel,   BorderLayout.NORTH);

}

ComboBoxModelArtikel

public class ComboBoxModelArtikel implements ComboBoxModel{
ConfigToolScannersPanel panel;   List<Artikel> lstArtikels; 
private Object selectedItem;

public ComboBoxModelArtikel(ConfigToolScannersPanel panel, List<Artikel> artikels) {
     this.panel=panel;  this.lstArtikels=artikels;      
      }
public void setSelectedItem(Object anItem) {
    selectedItem=anItem;
      }
public Object getSelectedItem() {
    return selectedItem;
      }
public int getSize() {
    return lstArtikels.size();
      }
public Object getElementAt(int index) {
    return (Artikel)lstArtikels.get(index);
      }
public void addListDataListener(ListDataListener l) {
    //Todo:
      }
public void removeListDataListener(ListDataListener l) {
    //Todo:
      }
    }

ArtikelListRenderer()

class ArtikelListRenderer extends JLabel implements ListCellRenderer {
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    if (value != null) {
        Artikel artikels = (Artikel) value;
        setText(artikels.getName());
    } else{
        setText("Please select an item");
    }

    return this;
    }
 }
  • 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-31T15:24:22+00:00Added an answer on May 31, 2026 at 3:24 pm

    I recreated the problem in one class, and it seems to be working:

    package test;
    
    import java.awt.Component;
    import java.awt.Dimension;
    import java.util.ArrayList;
    import java.util.List;
    
    import javax.swing.ComboBoxModel;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.ListCellRenderer;
    import javax.swing.event.ListDataListener;
    
    public class ComboMain {
    
        public static void main(String[] args) {
            JFrame f = new JFrame();
            JComboBox<Artikel> cmb = new JComboBox<Artikel>(
                    new ComboBoxModelArtikel(null, readFromArtikel()));
            cmb.setRenderer(new ArtikelListRenderer());
            f.add(cmb);
            f.setSize(new Dimension(200, 200));
            f.setVisible(true);
        }
    
        public static List<Artikel> readFromArtikel() {
            List<Artikel> a = new ArrayList<Artikel>();
            a.add(new Artikel("id", "name"));
            a.add(new Artikel("id1", "name1"));
            return a;
        }
    
    }
    
    class Artikel {
        String id;
        String name;
    
        public Artikel(String id, String name) {
            this.id = id;
            this.name = name;
        }
    
        public String getName() {
            return this.name;
        }
    
    }
    
    
    class ArtikelListRenderer extends JLabel implements ListCellRenderer<Artikel> {
    
        @Override
        public Component getListCellRendererComponent(
                JList<? extends Artikel> list, Artikel value, int index,
                boolean isSelected, boolean cellHasFocus) {
            if (value != null) {
                Artikel artikels = (Artikel) value;
                setText(artikels.getName());
            } else {
                setText("Please select an item");
            }
    
            return this;
        }
    }
    
    class ComboBoxModelArtikel implements ComboBoxModel<Artikel> {
        private Object selectedItem;
        List<Artikel> lstArtikels;
        private Object panel;
    
        public ComboBoxModelArtikel(Object panel, List<Artikel> artikels) {
            this.panel = panel;
            this.lstArtikels = artikels;
        }
    
        public void setSelectedItem(Object anItem) {
            selectedItem = anItem;
        }
    
        public Object getSelectedItem() {
            return selectedItem;
        }
    
        public int getSize() {
            return lstArtikels.size();
        }
    
        public Artikel getElementAt(int index) {
            return lstArtikels.get(index);
        }
    
        public void addListDataListener(ListDataListener l) {
            // Todo:
        }
    
        public void removeListDataListener(ListDataListener l) {
            // Todo:
        }
    }
    

    Maybe the problem is in the WebComboBox

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

Sidebar

Related Questions

You have list of objects and each of them has an id property. Here's
I have List of User object, I just want to get User objects from
I have a list of objects and i want to bind this list with
i have a list of objects in a collection. Each object has a string
I have five strong-typed List objects. Every object inside every List have property Rating
I have a list of objects and I want to reorder them randomly on
I have list of transaction objects and want to order them by certain condition
I have List objects which are shown like this: www.mysite.com/lists/123 Where 123 is the
I have a list of objects and I want to remove all the ones
I have a list of objects: [Object_1, Object_2, Object_3] Each object has an attribute:

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.