I have a JTable in MVC model. In the controller I have an inner class called TablePopup. Here is the code:
class TablePopup extends JPopupMenu { public TablePopup(JTable table) { JMenuItem itemDelete = new JMenuItem("Delete row"); JMenuItem itemAdd = new JMenuItem("Add row"); itemDelete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { System.out.println("Delete row"); } }); itemAdd.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { System.out.println("Add row"); } }); add(itemDelete); add(new JSeparator()); add(itemAdd); }// End of inner Class TablePopUp
I want to add a popup menu to a Jtable which is initialezed in the view.
In the controller I do:
tablePopup = new TablePopup(table); table.addMouseListener(new MouseAdapter() { public void mouseReleased (MouseEvent e) { if (e.isPopupTrigger()) { System.out.println("Popup Trigger!"); tablePopup.show (e.getComponent(), e.getX(), e.getY()); } } });
I get the System.out.println("Popup Trigger!"); but the popup does not come up. When I right click, I see a small white panel but it is only there for a second.