Class UIScale


  • public class UIScale
    extends java.lang.Object
    Two scaling modes are supported for HiDPI displays: 1) system scaling mode This mode is supported since Java 9 on all platforms and in some Java 8 VMs (e.g. Apple and JetBrains). The JRE determines the scale factor per-display and adds a scaling transformation to the graphics object. E.g. invokes java.awt.Graphics2D.scale( 1.5, 1.5 ) for 150%. So the JRE does the scaling itself. E.g. when you draw a 10px line, a 15px line is drawn on screen. The scale factor may be different for each connected display. The scale factor may change for a window when moving the window from one display to another one. 2) user scaling mode This mode is mainly for Java 8 compatibility, but is also used on Linux or if the default font is changed. The user scale factor is computed based on the used font. The JRE does not scale anything. So we have to invoke scale(float) where necessary. There is only one user scale factor for all displays. The user scale factor may change if the active LaF, "defaultFont" or "Label.font" has changed. If system scaling mode is available the user scale factor is usually 1, but may be larger on Linux or if the default font is changed.
    • Constructor Summary

      Constructors 
      Constructor Description
      UIScale()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addPropertyChangeListener​(java.beans.PropertyChangeListener listener)  
      static javax.swing.plaf.FontUIResource applyCustomScaleFactor​(javax.swing.plaf.FontUIResource font)
      Applies a custom scale factor given in system property "flatlaf.uiScale" to the given font.
      static double getSystemScaleFactor​(java.awt.Graphics2D g)  
      static double getSystemScaleFactor​(java.awt.GraphicsConfiguration gc)  
      static float getUserScaleFactor()  
      static boolean isSystemScalingEnabled()  
      static void removePropertyChangeListener​(java.beans.PropertyChangeListener listener)  
      static float scale​(float value)  
      static int scale​(int value)  
      static java.awt.Dimension scale​(java.awt.Dimension dimension)  
      static java.awt.Insets scale​(java.awt.Insets insets)  
      static int scale2​(int value)
      Similar as scale(int) but always "rounds down".
      static void scaleGraphics​(java.awt.Graphics2D g)  
      static float unscale​(float value)  
      static int unscale​(int value)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • UIScale

        public UIScale()
    • Method Detail

      • addPropertyChangeListener

        public static void addPropertyChangeListener​(java.beans.PropertyChangeListener listener)
      • removePropertyChangeListener

        public static void removePropertyChangeListener​(java.beans.PropertyChangeListener listener)
      • isSystemScalingEnabled

        public static boolean isSystemScalingEnabled()
      • getSystemScaleFactor

        public static double getSystemScaleFactor​(java.awt.Graphics2D g)
      • getSystemScaleFactor

        public static double getSystemScaleFactor​(java.awt.GraphicsConfiguration gc)
      • applyCustomScaleFactor

        public static javax.swing.plaf.FontUIResource applyCustomScaleFactor​(javax.swing.plaf.FontUIResource font)
        Applies a custom scale factor given in system property "flatlaf.uiScale" to the given font.
      • getUserScaleFactor

        public static float getUserScaleFactor()
      • scale

        public static float scale​(float value)
      • scale

        public static int scale​(int value)
      • scale2

        public static int scale2​(int value)
        Similar as scale(int) but always "rounds down".
      • unscale

        public static float unscale​(float value)
      • unscale

        public static int unscale​(int value)
      • scaleGraphics

        public static void scaleGraphics​(java.awt.Graphics2D g)
      • scale

        public static java.awt.Dimension scale​(java.awt.Dimension dimension)
      • scale

        public static java.awt.Insets scale​(java.awt.Insets insets)