Deselection « JList « Java Swing Q&A





1. JList deselection problem    coderanch.com

not sure I'm reading this correct to deselect:- list.clearSelection(); to find out of a de-selection - in valueChanged() check for list.getSelectedIndex() == -1 something like this import javax.swing.*; import javax.swing.event.*; import java.awt.event.*; import java.awt.*; class JListDemo extends JFrame implements ActionListener, ListSelectionListener { DefaultListModel listModel = new DefaultListModel(); JList list = new JList(listModel); JButton btn = new JButton("De-select"); public JListDemo() { super("JList ...

2. JList Deselection    coderanch.com

Found some of this code on google then did some slight mods to make it work. protected class ListEventMonitor implements ListSelectionListener { public void valueChanged(ListSelectionEvent e) { // The list that has been changed. JList listSource = (JList) e.getSource(); // Gain access to the list data. ListModel data = listSource.getModel(); // Get the boundaries of the change. final int first = ...