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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:17:45+00:00 2026-05-27T06:17:45+00:00

In reference to this: How do I display something I enter in a JOptionPane

  • 0

In reference to this: How do I display something I enter in a JOptionPane on the JFrame?

I’ve made a JList which also outputs what I’ve inputted, and it displays on the JPanel as JLabels, as what I’ve done using the link. However, how do I remove the respective JLabels this time? Thanks so much to anyone who will help!

Edit:
What I want to do is when I click the remove button in my JList, the label on the panel will also be removed.

  • 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-27T06:17:46+00:00Added an answer on May 27, 2026 at 6:17 am

    I’ll add an answer to provide some code since I have the feeling my comments are misunderstood.

    First, if it isn’t necessary, don’t use a label per list entry but use one label whose contents is a concatenation of the list entries. Then update the label’s text whenever the list changes.

    Basically, you have a method like this:

    private void updateLabel() {
       StringBuilder text = new StringBuilder();
       //this assumes listModel is a DefaultListModel and doesn't contain null values
       //adapt for other list models and add any necessary checks
       for( Object entry : listModel.toArray() ) {
         text.append( entry.toString()).append(" ");
       }
       label.setText( text.toString() );
    }
    

    Then add a listener to your list model:

    listModel.addListDataListener( new ListDataListener() {      
      public void intervalAdded(ListDataEvent e) {
         updateLabel();
      }
    
      public void intervalRemoved(ListDataEvent e) {
         updateLabel();
      }
    
      public void contentsChanged(ListDataEvent e) {
         updateLabel();
      }
    });
    

    Thus, when you change something in the list the label would be updated automatically.

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

Sidebar

Related Questions

I'm writing this question with reference to this one which I wrote yesterday. After
Is it OK to reference this when initializing a field? public class MainClass {
In reference to this answer to a Stack Overflow question : what is bench-testing
With the reference of this answer , what is Theta (tight bound)? Omega is
an svn:externals reference like this dojo -r 21434 http://svn.dojotoolkit.org/src/dojo/trunk/ is happily accepted by subversive
I'm currently creating an explicit reference to this in the outer class so that
I'm trying to find any reference for this function, but I haven't found anything.
I am doing pass-by-reference like this: use strict; use warnings; sub repl { local
i have 3 hidden fields in 1 div. when I have reference to this
when i search for open source for domain checker, i got this reference http://www.codeproject.com/KB/aspnet/DataScraping.aspx

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.