Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8087565

Scaling problem on OSX Retina

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8u40, 9
    • Fix Version/s: 9
    • Component/s: javafx
    • Environment:

      Macbook Pro 13" with Retina Display (HiDpi)
      External display Samsung Syncmaster S22C450 with 1680 x 1050 (no HiDpi)

      Backports

        Description

        Since 8u40 there is a problem with app scaling on Retina Displays, when stage.show() is done while the initialize-method of a Component.

        Steps to reproduce:
        .) Connect external display to macbook
        .) Set external display as mainpanel.
        .) set "parentStage.setX(0);" in FxmlComponent.java
        .) Startup RetinaTest.java
        .) JavaFX app should be displayed on external display and everything should be fine
        .) close JavaFX app
        .) set "parentStage.setX(.....);" to a value that the app will be displayed on retina display
        .) wrong scaling

        Also tried it with 8u31 and 8u25 => everything is fine.
        Anyways this stage.show() in initialize method was a ugly hack in our app, so we won't this anymore.





        ***********************************
        RetinaTest.java
        ***********************************

        package sample;

        import javafx.application.Application;
        import javafx.scene.Scene;
        import javafx.stage.Stage;

        public class RetinaTest extends Application {
            public static void main(String[] args) {
                launch(args);
            }
            @Override
            public void start(Stage stage) throws Exception {
                FxmlComponent root = new FxmlComponent(stage);
                stage.setScene(new Scene(root));
            }
        }



        ***********************************
        FxmlComponent.java
        ***********************************

        package sample;

        import javafx.event.ActionEvent;
        import javafx.fxml.FXML;
        import javafx.fxml.FXMLLoader;
        import javafx.fxml.Initializable;
        import javafx.scene.control.Label;
        import javafx.scene.layout.AnchorPane;
        import javafx.stage.Stage;

        import java.io.IOException;
        import java.net.URL;
        import java.util.ResourceBundle;

        public class FxmlComponent extends AnchorPane implements Initializable {

            private Stage parentStage;

            @FXML
            private Label label;

            public FxmlComponent(Stage parentStage) {
                this.parentStage = parentStage;

                FXMLLoader fxmlLoader = new FXMLLoader();
                fxmlLoader.setLocation(getClass().getResource("FxmlComponent.fxml"));
                fxmlLoader.setRoot(this);
                fxmlLoader.setController(this);
                try {
                    fxmlLoader.load();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @FXML
            private void handleButtonAction(ActionEvent event) {
                System.out.println("You clicked me!");
                label.setText("Hello World!");
            }

            @Override
            public void initialize(URL url, ResourceBundle rb) {
                
                //set X to a value, that it will be moved to retina screen
                parentStage.setX(3000);
                parentStage.setY(100);

                parentStage.setWidth(150);
                parentStage.setHeight(70);
                parentStage.show();
            }
        }



        ***********************************
        FxmlComponent.fxml
        ***********************************

        <?xml version="1.0" encoding="UTF-8"?>
        <?import javafx.scene.control.Button?>
        <?import javafx.scene.control.Label?>
        <fx:root xmlns:fx="http://javafx.com/fxml"
                 type="sample.FxmlComponent">
            <children>
                <Button id="button" layoutX="5" layoutY="5" text="Click Me!" onAction="#handleButtonAction" fx:id="button" />
                <Label id="label" layoutX="5" layoutY="35" minHeight="16" minWidth="70" prefHeight="16" prefWidth="70" fx:id="label" />
            </children>
        </fx:root>

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                flar Jim Graham
                Reporter:
                duke J. Duke (Inactive)
                Votes:
                1 Vote for this issue
                Watchers:
                8 Start watching this issue

                  Dates

                  Due:
                  Created:
                  Updated:
                  Resolved:
                  Imported: