JDK-8145516 : Scene content shows too large on Retina display, when a regular screen attached
  • Type: Bug
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: 8u66
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: other
  • CPU: x86
  • Submitted: 2015-12-14
  • Updated: 2017-09-07
  • Resolved: 2016-06-22
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 JDK 9
8u112Fixed 9Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
1.8.0_66

ADDITIONAL OS VERSION INFORMATION :
Mac OS X 10.11.1, El Capitan

EXTRA RELEVANT SYSTEM CONFIGURATION :
Running on MacBook Pro 13", Retina, but with a regular screen attached through DisplayPort.

A DESCRIPTION OF THE PROBLEM :
When I have my non-Retina screen attached to my MacBook, my application's Scenes display far too large on the Retina screen. If I drag the window onto the non-Retina screen, they are corrected, when I drag the window back onto Retina, it remains correct. However, if my application opens another window, that Scene is far too large, until again, I drag it onto the non-Retina screen, and back onto the Retina screen.

I have found that this only ever happens if my non-Retina screen is set as the primary screen in System Preferences, i.e. if the Mac menu bar is on the non-Retina screen. If I keep the Retina screen as the primary display, there is no bug. With only the Retina screen in use, there is no bug.

It would appear that having the non-Retina screen as the primary display is the deciding factor of whether this bug happens, so perhaps on creating a Stage, the DPI it's getting from Screen is for the primary display, not the display the Stage is open on.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
This is easily replicate with:

1) Create new JavaFX/FXML project in NetBeans.
2) In the 'start' method, insert 'stage.setX(2500);', this will push the window off the external display and onto the laptop display, with the Scene displayed too large. More/less than 2500 will be needed depending on the pixel width of the external display. 

This will only work if the external display is the 'primary' display in System Preferences, i.e. it has the 'menu bar' in it in the Preferences window. If the Retina display is primary, no bug occurs.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would like the Scene to display at the correct size.
ACTUAL -
The Scene display far too large, looks about twice the size it should be, which makes sense.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
No crash, just displays far too big.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package retina;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

/**
 *
 * @author gt
 */
public class Retina extends Application {
    
    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
        
        Scene scene = new Scene(root);
        stage.setX(2500);
        stage.setScene(scene);
        stage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
    
}

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

CUSTOMER SUBMITTED WORKAROUND :
I can drag the window onto my non-Retina display and back again onto my Retina display, although this bug will prevent shipping.


Comments
Changeset: 4ae5bcc8da10 Author: flar Date: 2016-06-21 17:30 -0700 URL: http://hg.openjdk.java.net/openjfx/9-dev/rt/rev/4ae5bcc8da10 8145516: Scene content shows too large on Retina display, when a regular screen attached Reviewed-by: kcr ! modules/graphics/src/main/native-glass/mac/GlassWindow+Java.m
22-06-2016

Approved to backport to 8u-dev (8u112).
21-06-2016

+1
21-06-2016

Raising to P3 as this is a good candidate for back-porting to 8u-dev to fix a problem that makes an app mostly unusable on multi-screen retina (there is a workaround, but many users may never figure it out).
17-06-2016

webrev: http://cr.openjdk.java.net/~flar/JDK-8145516/webrev.00/ It looks like if a change of screen occurs before a window is made visible, we are not notified of the change in the backing store scales. The fix is to manually update the scale when we make the window visible. The added code is taken directly from the GlassWindow+Overrides.m implementation of windowDidChangeBackingProperties (which is the method notified by the system when scale changes happen when the window is mapped).
17-06-2016

I've upgraded to 10.11 and am able to reproduce it now...
18-04-2016

I'm not able to reproduce this with 8u-dev or 9-dev on either 10.8 or 10.10. I don't have an El Capitan (10.11) partition to test that on. Does it reproduce on earlier MacOS releases?
06-01-2016