JavaFX contextmenu not hiding -
i'm trying show context menu when there selected in list view. called hide in on showing event. however, not working. context menu still shows up. bug, or not intended use? because javafx api seems suggest hide() suppose this.
anyway code.
contextmenu menu = new contextmenu(); menu.setonshowing(new eventhandler<windowevent>() { @override public void handle(final windowevent event) { menu.hide(); } });
it probably work if do
public void handle(final windowevent event) { platform.runlater(new runnable() { @override public void run() { menu.hide(); } }); }
but seems horrible hack.
why not set context menu if selected?
final listview<t> listview = ... ; final contextmenu menu = new contextmenu(); listview.getselectionmodel().selecteditemproperty().addlistener(new changelistener<t>() { @override public void changed(observablevalue<? extends t> obs, t oldvalue, t newvalue) { if (newvalue == null) { listview.setcontextmenu(null); } else { listview.setcontextmenu(menu); } } });
(obviously replace t
whatever type listview
displaying).
Comments
Post a Comment