I've found a Swing image rendering bug which afflicts only Macs with Retina displays (TYPE_INT_ARGB_PRE BufferedImages fail to draw). I have an effective workaround (use TYPE_INT_ARGB images instead), but in order to apply it, I need to be able to detect whether the host machine is a Mac with a Retina display. Detecting whether the machine is a Mac is no problem, but how can I determine the display type?
Asked
Active
Viewed 1,434 times
7
uckelman
- 24,228
- 8
- 61
- 80
2 Answers
15
Toolkit.getDefaultToolkit().getDesktopProperty("apple.awt.contentScaleFactor")
The above line should return 2.0 on retina displays. On more recent non-retina macs it returns 1.0 and on all other platforms you get back null. I can't find any official documentation, but I ran across it in this mailing list post while trying to solve a similar problem.
job
- 8,655
- 7
- 40
- 50
-
1This is not a good method because users may have multiple monitors, one of which is Retina and one which isn't. You need to query this state for individual windows each time you repaint. – Steve McLeod Feb 12 '14 at 18:12
-
This returns null on my late 2013 rMBP. Is there somewhere specific it should be used? – dmolony Feb 14 '17 at 20:01