I want to add a right click popupmenu to a JTable in NetBeans IDE (seems like a simple task... lol)
I got it to partly work by
But this only partly works. Now I when I right click on the Table the menu pops up, but the selected row in the JTable does not change. So in when the menuitem's actionPerformed is called I have no idea what row in the JTable was clicked on.
How can I get this? or is there an easier way to do this in netbeans?
I know there are others ways of doing this (in code), but I would prefer to use netbeans GUI builder.
Has anyone ever done this before?
Thanks for your help!
Why do you rely on an IDE to generate code for you? What happens when you move to a different IDE and you have to learn how to do it for that ide? Learn how to write your own code then the IDE doesn't matter:
table.addMouseListener( new MouseAdapter()
{
public void mouseReleased(MouseEvent e)
{
if (e.isPopupTrigger())
{
JTable source = (JTable)e.getSource();
int row = source.rowAtPoint( e.getPoint() );
int column = source.columnAtPoint( e.getPoint() );
if (! source.isRowSelected(row))
source.changeSelection(row, column, false, false);
popup.show(e.getComponent(), e.getX(), e.getY());
}
}
});