How do you detect a Retina Display in Java?

java, retina-display

Solution

I would get the value this way -

public static boolean hasRetinaDisplay() {
  Object obj = Toolkit.getDefaultToolkit()
      .getDesktopProperty(
          "apple.awt.contentScaleFactor");
  if (obj instanceof Float) {
    Float f = (Float) obj;
    int scale = f.intValue();
    return (scale == 2); // 1 indicates a regular mac display.
  }
  return false;
}

Problem

How can I detect if a user has a retina display in Java? I am already aware of detecting the scale factor using `Toolkit.getDefaultToolkit().getDesktopProperty("apple.awt.contentScaleFactor")`, but java won't let me convert the returned value into an int. I'm wondering how I can convert that into an int, or another way to detect retina displays.

Original source