Cancel mode event to hide contextmenus?
Anthony Petrov
anthony.petrov at oracle.com
Tue Feb 19 05:01:47 PST 2013
Hi Werner,
I believe you're facing this issue:
http://javafx-jira.kenai.com/browse/RT-24632
It's fixed in 8.0 for quite some time already. Could give it a try with
a recent 8.0 build and see if it "just works" w/o all these custom
listeners?
For your convenience here's a link:
http://jdk8.java.net/download.html
FX is bundled with the JDK build.
--
best regards,
Anthony
On 2/19/2013 16:08, Werner Lehmann wrote:
> Hi,
>
> I am still having a hard time to make sure that contextmenus are hidden
> when the user moves or resizes the window underneath. This is on a
> JFXPanel, not sure if it is a problem in a pure FX application, too.
>
> Currently this requires quite some code, see below for a snippet. And
> this works only if I actually have a reference to all contextmenus which
> could possibly be showing on a scene. Which is also a problem because on
> MenuButton and other controls the contextmenu is an implementation
> detail and it is intentionally hard or impossible to get a reference to
> those.
>
> On Win32 there is a WM_CANCELMODE event sent to controls which stops
> editing, unreleases mouse captures, and also closes menus. Is there
> something similar in FX which I could send to a root container to
> achieve this on every child control?
>
> Rgds
> Werner
>
> PS: for your "amusement", this is what I am currently doing to hide the
> menu IF I have a reference to it:
>
> 1. Wait until control is added to scene.
> 2. Wait until scene has a window.
> 3. Listen to changes on the window x/y/width properties to hide the
> contextmenu (don't need to listen to height property in this case).
>
>> sceneProperty().addListener(new InvalidationListener() {
>> @Override
>> public void invalidated(Observable arg0)
>> {
>> Scene s = getScene();
>> if (s != null)
>> {
>> s.windowProperty().addListener(new InvalidationListener() {
>> @Override
>> public void invalidated(Observable arg0)
>> {
>> if (getScene() != null && getScene().getWindow() != null)
>> {
>> ChangeListener<Number> changeListener = new
>> ChangeListener<Number>() {
>> @Override
>> public void changed(ObservableValue<? extends
>> Number> observableValue, Number oldValue, Number newValue)
>> {
>> cmUser.hide();
>> }
>> };
>>
>> getScene().getWindow().xProperty().addListener(changeListener);
>>
>> getScene().getWindow().yProperty().addListener(changeListener);
>>
>> getScene().getWindow().widthProperty().addListener(changeListener);
>> }
>> }
>> });
>> }
>> }
>> });
>
More information about the openjfx-dev
mailing list