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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:52:38+00:00 2026-05-22T20:52:38+00:00

I’m making enhancements to a Swing app (never done Swing programming before), and need

  • 0

I’m making enhancements to a Swing app (never done Swing programming before), and need to be able to make a single text item in a JList bold. I’ve seen a few posts where they said to just put "<html><b>" and "</b></html>" around the string. Are you serious, that seems like such a hack. It’s also possible in the future that we’ll want to change the background color of an item in the JList – would that also be possible with HTML tags?

Another suggestion I’ve seen is to call the setCellRenderer() method on the JList with your own object that implements the ListCellRenderer interface. But I’m not sure that can do what we want. It seems the ListCellRenderer has a getListCellRendererComponent() method where you set how an item will be displayed depending on whether it is selected or has the focus. But we want to have one item in the JList be bold depending on what our business logic determines, and it may be an item that is neither selected nor has the focus. I haven’t seen any good examples of this ListCellRenderer, so I’m not sure if it’s the approach we want.

  • 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-22T20:52:39+00:00Added an answer on May 22, 2026 at 8:52 pm

    The ListCellRenderer component also gets the object to be displayed and thus you can format based on whatever logic you have to. You can find the introduction to custom rendering here and an example of a renderer here (it sets the background based on dnd location but the idea is the same for other logic as well).

    The following code gives you an idea of how it may be implemented.

    class MyCellRenderer extends DefaultListCellRenderer {
    
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    
            if ("TEST".equals(value)) {// <= put your logic here
                c.setFont(c.getFont().deriveFont(Font.BOLD));
            } else {
                c.setFont(c.getFont().deriveFont(Font.PLAIN));
            }
            return c;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.