How do I encode when an item was selected in a JList?

I have a JList with 5 parameters in it, and when one of the elements is selected or clicked, I want the text area next to it to display a paragraph of text relative to the clicked element. It should do this for each item in the list, but I cannot find how to do this in the API

How will my program know if an item has been selected in a JList so that I can work with data?

+3
source share
2 answers

Use addListSelectionListener. You can create a subclass (anonymous or not) ListSelectionListenerthat does the job.

myList.addListSelectionListener(new ListSelectionListener()
{
  public void valueChanged(ListSelectionEvent ev)
  {
    // handle ev
  } 
});
+8
source

JList. Swing , .

+1

Source: https://habr.com/ru/post/1751677/


All Articles