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

JFXPanel sends resize event with size 0x0 on HiDPI devices

XMLWordPrintable

    • b26
    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10, monitor with HiDPI settings

      A DESCRIPTION OF THE PROBLEM :
      If the scaleFactors used for the current device are not 1.0, a JXFPanel will send a resize event with 0x0 dimensions to the JavaFX scene. For some components this undesirable effects like flickering or parts being smaller than they should.
      The code sending the event is in JFXPane.updateComponentSize():
      if (oldWidth != pWidth || oldHeight != pHeight ||
                  newScaleFactorX != scaleFactorX || newScaleFactorY != scaleFactorY)
      At the beginning, oldWidth==pWidth==oldHeight==pHeight==0, but the scale factors changed. Actually, it is not even necessary to resize the pixel buffer in that case.

      REGRESSION : Last worked in version 8u221

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      On a Windows system, configure a monitor to display with 125% scaling or more.
      Run the ZeroSizeTester and click the button.
      Check the contents of the text area.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      new width: 250.0
      new width: 184.0 (or similar)
      That is actually what happens without extra scaling.
      ACTUAL -
      new width: 250.0
      new width: 0.0 <--- this is not so nice
      new width: 186.0 (or similar)

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

      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.SwingUtilities;
      import javax.swing.WindowConstants;

      import javafx.application.Platform;
      import javafx.embed.swing.JFXPanel;
      import javafx.scene.Scene;
      import javafx.scene.control.TextArea;

      public class ZeroSizeTester
      {
         private JFrame frame;

         public static void main(String[] args)
         {
            new ZeroSizeTester().init();
         }

         private void init()
         {
            JFXPanel fxPanel = new JFXPanel();
            frame = new JFrame();
            frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

            JButton button = new JButton("Click");
            button.addActionListener(e ->
                                     {
                                        frame.remove(button);
                                        Platform.runLater(() -> initFX(fxPanel));
                                     });

            frame.add(button);
            frame.pack();
            frame.setSize(200, 200);
            frame.setVisible(true);
         }

         private void initFX(JFXPanel fxPanel)
         {
            Scene scene = createScene();
            fxPanel.setScene(scene);
            SwingUtilities.invokeLater(() ->
                                       {
                                          frame.add(fxPanel);
                                          frame.revalidate();
                                       });
         }

         private Scene createScene()
         {
            TextArea textArea = new TextArea();
            textArea.setMaxWidth(Integer.MAX_VALUE);
            textArea.widthProperty().addListener((obs, oldValue, newValue) -> textArea.setText(textArea.getText() + "\nnew width: " + newValue));
            textArea.setPrefWidth(250);
            textArea.setPrefHeight(250);

            return new Scene(textArea);
         }
      }

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

      FREQUENCY : always


            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: