addListSelectionListener
public void addListSelectionListener(ListSelectionListener listener)
Adds a listener to the list that's notified each time a change to the selection occurs. Listeners added directly to the JList will have their ListSelectionEvent.getSource() == this JList (instead of the ListSelectionModel). Parameters:
listener - the ListSelectionListener to add
public void addListSelectionListener(ListSelectionListener listener)
Adds a listener to the list that's notified each time a change to the selection occurs. Listeners added directly to the JList will have their ListSelectionEvent.getSource() == this JList (instead of the ListSelectionModel). Parameters:
listener - the ListSelectionListener to add
import javax.swing.JList;
JList jList1 = new JList(); class SymMouse extends java.awt.event.MouseAdapter
{
public void mouseClicked(java.awt.event.MouseEvent e)
{
Object object = e.getSource();
if(object==jList1)
jList1_mouseClicked(e);
}
} void jList1_mouseClicked(java.awt.event.MouseEvent event)
{
if(event.getModifiers()==MouseEvent.BUTTON1_MASK&&event.getClickCount()==2)
{
JOptionPane.showMessageDialog(this,"正在测试","警告",JOptionPane.WARNING_MESSAGE);
}
}
SymMouse picker = new SymMouse()
jList1.addMouseListener(picker);
还要加上这么一个包