Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>I don't know how to select one image.</p> </blockquote> <ul> <li><p><code>JList</code> uses an instance of <code>ListSelectionModel</code> to manage its selection. By default, a list selection model allows any combination of items to be selected at a time. You can specify a different selection mode(i.e, <em>single item selection</em>) by calling the <a href="http://docs.oracle.com/javase/7/docs/api/javax/swing/JList.html#setSelectionMode%28int%29" rel="nofollow"><code>setSelectionMode()</code></a> method on the list.</p> <pre><code> jList1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); </code></pre></li> <li><p>To do, on item selection event with <code>JList</code>, use the <code>ListSelectionListener</code> to select your item. </p> <pre><code> jList1.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { JList jlist = (JList) e.getSource(); Object curentSelectedObject = jlist.getModel().getElementAt(e.getFirstIndex()); Object lastSelectedObject = jlist.getModel().getElementAt(e.getLastIndex()); } }); </code></pre></li> </ul> <p>Using <code>ListSelectionListener</code> is preferable over using <code>MouseListener</code> with <code>JList</code>. Unlike <code>MouseListener</code>, being simple and higher level, it has other two functions <code>evt.getFirstIndex()</code> and <code>evt.getLastIndex()</code> which is very useful. </p> <p><strong>Tutorial resource:</strong></p> <ol> <li><a href="http://docs.oracle.com/javase/tutorial/uiswing/events/listselectionlistener.html" rel="nofollow">How to Write a List Selection Listener</a></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload