GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes Right click in JList item Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Right click in JList item" Watch "Right click in JList item" New topic
Author

Right click in JList item

Nathan Paris
Greenhorn

Joined: Jun 21, 2000
Posts: 28
I have a JList and need to know how to right click on a specific Item in the list. I.e. the list will have some items and a right click would bring up a Menu for that item.
Thanks,
Nathan
San Su
Ranch Hand

Joined: Jul 06, 2001
Posts: 313

Right click will not select an item in JList. To poptup menu
on right click, you need to add mouseListener to JList
and listen for mousePressed event.
public void mousePressed( MouseEvent e ){
if (SwingUtilities.isRightMouseButton(e)){
// Right mouse button is pressed.
// Add popup menu code here..
}
}
Sankar S.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Right click in JList item