event handling - Why is a MenuItem not responding? -
there contextmenu has 2 options , when second option (item2 in code) pressed right mousebutton want print out text know did activate it. till nothing happens when click on second mousebutton.
i haven't had experience yet eventhandlers apologies if made noobish mistake.
private void maakcontextmenu() { menu = new contextmenu(); menuitem item = new menuitem("kleur assen"); menuitem item2 = new menuitem("tweede optie"); final lissajouscanvas canvas = this; item.setonaction(new eventhandler<actionevent>() { @override public void handle(actionevent event) { new kieskleur(canvas).show(); } }); item2.addeventhandler(mouseevent.mouse_clicked, new eventhandler<mouseevent>(){ @override public void handle(mouseevent t) { system.out.println("in loop"); if(t.getsource()==mousebutton.secondary){ system.out.println("in deep"); } new kieskleur(canvas).show(); } }); menu.getitems().addall(item, item2); }
a menuitem
not node
, it's not part of scene graph in way node
s are. i'm not sure if bug or not; think implements eventtarget
can generate actionevent
s. you'll have noticed there no setonmouseclicked(...)
method available.
here's workaround. i'm not sure why works mouse_pressed
, not mouse_clicked
, it's default mouse event handling generates action events:
private void maakcontextmenu() { menu = new contextmenu(); menuitem item = new menuitem("", new label("kleur assen")); label menuitem2label = new label("tweede optie"); menuitem item2 = new menuitem("", menuitem2label); final lissajouscanvas canvas = this; item.setonaction(new eventhandler<actionevent>() { @override public void handle(actionevent event) { new kieskleur(canvas).show(); } }); menuitem2label.addeventhandler(mouseevent.mouse_pressed, new eventhandler<mouseevent>(){ @override public void handle(mouseevent t) { system.out.println("in loop"); if(t.getbutton()==mousebutton.secondary){ system.out.println("in deep"); } new kieskleur(canvas).show(); } }); menu.getitems().addall(item, item2); }
Comments
Post a Comment