JDK-8169777 : MenuBar unoperable after moving Application to second monitor
  • Type: Bug
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: 8u111
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: other
  • CPU: x86
  • Submitted: 2016-11-15
  • Updated: 2017-02-17
  • Resolved: 2017-01-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8u152 b01Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.14393]

EXTRA RELEVANT SYSTEM CONFIGURATION :
Dual-Monitor setup with 4K resolution on both monitors.
Primary monitor is an external screen (Windows rescaling factor = 150%)
Secondary monitor is a laptop screen (Windows rescaling factor = 200%)

A DESCRIPTION OF THE PROBLEM :
When I run any JavaFX Application with a MenuBar, the menu ceases to work as soon as I move the application from my primary to my secondary monitor. I am still able to click on the Menus in the MenuBar, but as soon as I release my mouse button the popup disappears. This makes it impossible to click on any of the items in the menu bar. Accessing the items via keyboard still works as expected.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Launch any JavaFX Application with a MenuBar on your primary screen
2. Move the Application to your secondary screen
3. Attempt to click on one of the MenuItems

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The MenuItem's action is triggered
ACTUAL -
The MenuBar's popup is only shown for as long as you hold the mouse button and you cannot trigger any of the actions. In some cases, the popup also appears on the wrong location on the screen...

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package sample;

import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextArea;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        TextArea console = new TextArea();
        MenuBar menuBar = createMenuBar(console);

        Parent root = new VBox(menuBar, console);
        primaryStage.setTitle("Excelsior JET GUI Test");
        primaryStage.setScene(new Scene(root, 300, 275));
        primaryStage.show();
    }

    private MenuBar createMenuBar(final TextArea console) {
        MenuItem printHelloWorld = new MenuItem("_Print Hello World");
        printHelloWorld.setOnAction(e -> console.appendText("Hello World\n"));

        MenuItem clearConsole = new MenuItem("_Clear Console");
        clearConsole.setOnAction(e -> console.clear());

        Menu fileMenu = new Menu("_File");
        fileMenu.getItems().add(printHelloWorld);
        fileMenu.getItems().add(clearConsole);

        return new MenuBar(fileMenu);
    }

    public static void main(String[] args) {
        launch(args);
    }
}

---------- END SOURCE ----------


Comments
http://hg.openjdk.java.net/openjfx/8u-dev/rt/rev/e97b999a16cd
13-01-2017

Looks good. Approved for backport to 8u-dev for 8u152. +1
13-01-2017

Testing completed on Windows 7 as well now.
12-01-2017

The fix was virtually identical to the fix for JDK-8160073 except that there weren't separate X&Y scale factors. Also, JDK9 has to deal with the view offsets changing on each screen so additional code was required at the native level to handle DPICHANGED events that is not needed in JDK8 where we only deal with a single "System DPI" and the location of the view on the window is the same on all screens. http://cr.openjdk.java.net/~flar/JDK-8169777/webrev.00/
06-01-2017

The fix would be similar to the code in JDK-8160073 but since 8u-dev does not have separate X & Y scales, it would have to be adapted to the 8u-dev code base with some slight modifications.
20-12-2016

Much of the coordinate scaling code in 8u-dev currently has lines that look like: postEvent(windowRelativeX / platformScale, winowRelativeY / platformScale, absoluteX / platformScale, absoluteY / platformScale) The correct code looks more like this: postEvent(windowRelativeX / platformScale, winowRelativeY / platformScale, screenX + (absoluteX - screenPlatformX) / platformScale, screenY + (absoluteY - screenPlatformY) / platformScale) The code base in 9 uses that pattern and the menus work fine. We need to backport those changes to 8u-dev.
20-12-2016

It most likely is a HiDPI bug. I seem to recall similar behavior in another bug fixed in 9 where the coordinates on menu events were not scaled correctly for secondary screens. The bug does not happen in 9. We should look to fix this in an upcoming 8uNNN release.
20-12-2016

This could be a Hi-DPI bug. We should try this on 9. We should also try this on 8u122-ea since some bugs have been fixed in this area.
16-11-2016