Skip to main content

Popup menu from jtable

1 reply [Last post]
WithCream
Offline
Joined: 2013-08-10
Points: 0

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

https://www.java.net//node/651807

Thanks.

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.
Peter-G
Offline
Joined: 2013-05-25
Points: 0

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 />
					selMonitor.show(e.getComponent(), e.getX() - 10, e.getY() - 10);<br />
				}<br />
			}<br />
		});</p>
<p>