title: JList - getting value from Click
body: <p>Is there any way to use ListSelectionListener or MouseAdapter to get information about selected value (if value is a String for example), is there any built-in method for that?</p>
  
  <p>I only know how to get proper indexes but not the content or content.toString()</p>
  
  <p>I'm adding element like this:</p>
  
  <pre><code>{
      DefaultListModel listModel;
  
      listModel.addElement(name);
  }
  </code></pre>
  
  <p>@Edit <br>
  Thank you for you for help.
  I solved my problem by doing this (for future generations so they wouldn't need to search as I did):</p>
  
  <blockquote>
  <pre><code>    list.addMouseListener(new MouseAdapter(){
            @Override
            public void mouseClicked(MouseEvent e) {
                System.out.println("Mouse click.");
                int index = list.getSelectedIndex();
                System.out.println("Index Selected: " + index);
                String s = (String) list.getSelectedValue();
                System.out.println("Value Selected: " + s.toString());
            }
      });
  </code></pre>
  </blockquote>