java - How can I do a popup menu without right click using awt or swing? -
i program popup menu similar context menu in java using awt or swing, need display when typing key, example "." looking por context menu needs right click. ¿how can it? idea... thanks.
start taking @ how use key bindings , how use menus, in particular bringing popup menu
basically, need register key binding against component specified key, , when it's corresponding actionperformed
event triggered, show popup menu...
inputmap im = getinputmap(when_in_focused_window); actionmap = getactionmap(); im.put(keystroke.getkeystroke(keyevent.vk_period, 0), "popup"); am.put("popup", new abstractaction() { @override public void actionperformed(actionevent e) { popup.pack(); dimension popupsize = popup.getpreferredsize(); int width = getwidth(); int height = getheight(); int x = (width - popupsize.width) / 2; int y = (height - popupsize.height) / 2; popup.show(testpane.this, x, y); } });
Comments
Post a Comment