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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:01:05+00:00 2026-05-16T02:01:05+00:00

Hopefully an easy question. From the example on http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/uiswing/components/combobox.html on Providing a Custom Renderer

  • 0

Hopefully an easy question.

From the example on http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/uiswing/components/combobox.html on “Providing a Custom Renderer” section, I can make a JComboBox like

Picture 3 - Text 3
-------------------
Picture 1 - Text 1
Picture 2 - Text 2
Picture 3 - Text 3
Picture 4 - Text 4
Picture 5 - Text 5

Where Picture 3 - Text 3 is the currently selected item.

Is it possible to have a custom label? Such as

Text 3
-------------------
Picture 1 - Text 1
Picture 2 - Text 2
Picture 3 - Text 3
Picture 4 - Text 4
Picture 5 - Text 5

Where the image is not displayed when the combo box is in it’s minimized state.

I’ve used a JButton/undecorated popup JFrame to emulate this before, but am wondering if it is possible to do with a pure JComboBox

Thanks

  • 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-16T02:01:06+00:00Added an answer on May 16, 2026 at 2:01 am

    Is it possible to have a custom label?
    Such as…

    Yes. The same renderer is used to render the drop down list and the selected item in the combo box. The selected value is renderer when the “renderer index” is -1, so you can customize the rendering however you want. Something like:

    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.plaf.basic.*;
    
    public class ComboBoxItemIcon extends JFrame
    {
        public ComboBoxItemIcon()
        {
            Vector model = new Vector();
            model.addElement( new Item(new ImageIcon("copy16.gif"), "copy" ) );
            model.addElement( new Item(new ImageIcon("add16.gif"), "add" ) );
            model.addElement( new Item(new ImageIcon("about16.gif"), "about" ) );
    
            JComboBox comboBox;
    
            comboBox = new JComboBox( model );
            comboBox.setRenderer( new ItemRenderer() );
            getContentPane().add(comboBox, BorderLayout.SOUTH );
        }
    
        class ItemRenderer extends BasicComboBoxRenderer
        {
            public Component getListCellRendererComponent(
                JList list, Object value, int index,
                boolean isSelected, boolean cellHasFocus)
            {
                super.getListCellRendererComponent(list, value, index,
                    isSelected, cellHasFocus);
    
                Item item = (Item)value;
    
                if (index == -1)
                {
                    setText( item.getText() );
                    setIcon( null );
                }
                else
                {
                    setText( item.getText() );
                    setIcon( item.getIcon() );
                }
    
                return this;
            }
        }
    
        class Item
        {
            private Icon icon;
            private String text;
    
            public Item(Icon icon, String text)
            {
                this.icon = icon;
                this.text = text;
            }
    
            public Icon getIcon()
            {
                return icon;
            }
    
            public String getText()
            {
                return text;
            }
        }
    
        public static void main(String[] args)
        {
            JFrame frame = new ComboBoxItemIcon();
            frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
            frame.pack();
            frame.setVisible( true );
         }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quick (and hopefully easy) question: I need to trigger a download of a PDF
Hopefully an easy question: I have added some docs to the index, where every
Hopefully this is an easy question. I'm using the ListBoxDragDropTarget from the Silverlight Toolkit
Hopefully an easy question. If I have an object and I want to call
This is hopefully an easy question to answer for someone familiar with Mozilla, but
Hopefully this will be an easy question! I have two tables, a 'client(s)' table
Hopefully this question has an easy answer. It's probably something stupid I'm doing! In
Hopefully a very easy question for you. I have a PHP object, one of
So I've got a hopefully easy question, but I don't understand why my code
Hopefully this is a quick and easy question to answer. Do I need 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.