jmenuitem - How to refresh item in a popup menu? -


i have popup menu (that comes out when user uses right click on specified elements), wich items readed list. want when item selected, item disabled in popupmenu (then if action happen return enabled). have implemented popupmenu, cannot implement enable/disable jmenuitem element. can me? thanks

    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);     } 

the way done using actions. actions extensions of actionlistener interface. can set action of, example, jmenuitem , in action can set enabled false. automatically disable jmenuitem. alternately can enable setting enabled true on action. here action api @oracle: action api java

and here discourse on how use actions: how use actions java


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -