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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:05:45+00:00 2026-05-21T10:05:45+00:00

I am working with JList and I have encountered a few design problems. what

  • 0

I am working with JList and I have encountered a few design problems.
what I want is a gui componenet that presents a list and lets the user add or remove values from it.

So I have created a class that receives a list

List<? exteds IDisplayable> 
  • IDisplayable is a simple interface that has String DisplayString(). every objects that wants to be displayed in the list needs to implement IDIsplayable.

When my GUI form loads I iterate over the list and do a

MylistModel.addElement(iDisplayable.getDisplayString()

This is because I don’t want it to display the toString(). So I added a method.

Now my question is how to return the list to the gui form that called it.
Should I iterate it and compare by name? This sounds awful.

I thing I need to put in my ListModel the object but display a different toString.
Should I create a new listmodel? I can’t even extend the AbstractListModel cause it uses toString.
Is that the only solution?

  • 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-21T10:05:45+00:00Added an answer on May 21, 2026 at 10:05 am

    As already mentioned, a xxRenderer is the collaborator which decides about all visual representation of an item shown in a “collection component” (such as JList, JTable, etc …). When stuck to core Swing support, the way to go is a implementing a custom renderer. SwingX supports a more lightweight approach by allowing to plug-in string display (and visual decorations, but that’s a story different from this): implement a custom StringValue (SwingX speak for string converter) and pass it to a SwingX renderer like

    StringValue sv = new StringValue() {
          @Override
          public String getString(Object value) {
              if (value instanceof MyObject) {
                  return .... // use MyObject properties to build a suitable rep
              }
              return TO_STRING.getString(value);
          }    
    }
    list.setCellRenderer(new DefaultListRenderer(sv));
    // a bit of beauty: same rep is re-usable in other collection components
    table.setCellRenderer(MyObject.class, new DefaultTableRenderer(sv);
    comboBox.setRenderer(list.getCellRenderer());
    tree.setTreeCellRenderer(new DefaultTreeRenderer(sv));
    

    In other words: SwingX supports a unified string representation throughout all of its collection components. The full power of that approach shows when sorting/filtering/searching: all that functionality automagically uses that custom string representation, that is the users by default sort/filter/search by what they see – no additional effort required by the developer 🙂

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

Sidebar

Related Questions

I have a JList which i want to use to display a list a
Working with Visual Studio (I'm using 2008) I have started to notice that when
Working with dates in ruby and rails on windows, I'm having problems with pre-epoch
Working with a SqlCommand in C# I've created a query that contains a IN
Working on a project at the moment and we have to implement soft deletion
Working on a project that parses a log of events, and then updates a
I've been looking through the Java API, but have had no luck in working
I’m working on an in-house app that tracks a bunch of tasks. I wanted
In a serious Java GUI app, you'll have models behind many of your GUI
Two web applications I'm working with are using the ASP.NET membership and each have

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.