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.
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:
Then add a listener to your list model:
Thus, when you change something in the list the label would be updated automatically.