Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to refresh item in a popup menu?
    primarykey
    data
    text
    <p>i have a popup menu (that comes out when the user uses right click on specified elements), wich items are readed from a list. I want that when an item is selected, that item is disabled in the popupMenu (then if some action happen it will return enabled). I have implemented the popupMenu, but i cannot implement this enable/disable JMenuItem element. Anyone can help me? Thanks</p> <pre><code> class PopupTriggerListener extends MouseAdapter { public void mousePressed(MouseEvent ev) { if (ev.isPopupTrigger()) { menu.show(ev.getComponent(), ev.getX(), ev.getY()); x = ev.getX(); y = ev.getY(); } } public void mouseReleased(MouseEvent ev) { if (ev.isPopupTrigger()) { menu.show(ev.getComponent(), ev.getX(), ev.getY()); x = ev.getX(); y = ev.getY(); } } public void mouseClicked(MouseEvent ev) { } } } JLabel label = new MyLabel("right-click"); public Test() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuItem item = new JMenuItem("Test1"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Menu item Test1"); JLabel newLabel = new JLabel("test"); label.add(newLabel); newLabel.setBounds(x, y, 40, 10); } }); menu.add(item); item = new JMenuItem("Test2"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Menu item Test2"); } }); menu.add(item); getContentPane().add(label); pack(); setSize(300, 100); } public static void main(String[] args) { new Test().setVisible(true); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload