view FinalThesis/src/RetinaScale_old.java @ 37:f7a79686256d default tip

update mid
author riono <e165729@ie.u-ryukyu.ac.jp>
date Mon, 17 Feb 2020 00:04:06 +0900
parents fce3f9c18d8d
children
line wrap: on
line source

public static int getRetinaScale(int shareScreenNumber) {
    int scale = 1;
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsDevice[] devices = env.getScreenDevices();

    try {
        Field field = devices[shareScreenNumber].getClass().getDeclaredField("scale");

        if (field != null) {
            field.setAccessible(true);
            Object retinaScale = field.get(devices[shareScreenNumber]);

            if (retinaScale instanceof Integer) {
                scale = (Integer) retinaScale;
                return scale;
            }
        }
    } catch (Exception ignore) {}
    return scale;
}