Created
May 14, 2012 10:45
-
-
Save carl-olin/2693254 to your computer and use it in GitHub Desktop.
Popup-menu for JList
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private class ParticipantListListener implements MouseListener { | |
private JList list; | |
private JPopupMenu menu; | |
public ParticipantListListener(JList list) { | |
this.list = list; | |
this.menu = new JPopupMenu(); | |
JMenuItem pm = new JMenuItem("Send Private Message"); | |
pm.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
System.out.println("skicka pm!"); | |
} | |
}); | |
JMenuItem file = new JMenuItem("Send File"); | |
file.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
System.out.println("skicka fil!"); | |
} | |
}); | |
menu.add(pm); | |
menu.add(file); | |
} | |
@Override | |
public void mouseClicked(MouseEvent e) { | |
list.setSelectedIndex(list.locationToIndex(e.getPoint())); | |
System.out.println(list.getSelectedIndex()); | |
menu.show(e.getComponent(), e.getX(), e.getY()); | |
} | |
@Override | |
public void mousePressed(MouseEvent e) {} | |
@Override | |
public void mouseReleased(MouseEvent e) {} | |
@Override | |
public void mouseEntered(MouseEvent e) {} | |
@Override | |
public void mouseExited(MouseEvent e) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment