Skip to main content

Popup menu from jtable

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2013-08-10

I'm converting a legacy XWindows/Motif gui to Java. I need to have a multi-level popup menu appear when a user selects a cell in the first column. The menu would give choices for that column. How would I associate a jmenu to a column? It needs to be for a single column only and be a left click with the mouse, not a right click. Different columns would have different menus. I did find an old thread in this forum that showed how to do it with a right click. I need to duplicate legacy functionality, though, so I need left click. Here's the previous thread


After further Googleing I found what appears to be the help I need. Here's the sample code.

public void mousePressed(MouseEvent e)
if(e.getButton() == MouseEvent.BUTTON1)
label.setText("Detected Mouse Left Click!");
else if(e.getButton() == MouseEvent.BUTTON3)
label.setText("Detected Mouse Right Click!");

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2013-05-25

That should work; using MouseEvent.BUTTON1.
I do this and it works on the left button.

<br />
Window3D w3d = new Window3D;<br />
		w3d.addMouseListener(new MouseAdapter(){<br />
			@Override<br />
			public void mousePressed(MouseEvent e){<br />
				if (e.isPopupTrigger()){<br />, e.getX() - 10, e.getY() - 10);<br />
				}<br />
			}<br />