MacBook – Java and Mac retina support

displayjavamacbook pro

Does Java support the retina display with high definition rendering of, for example, text? Or is it treated as an unmodified application, and therefore subject to scaling?

Best Answer

I just tested this on my MacBook Pro with retina, so the answer is yes and no - at least under Mountain Lion.

If you use Java directly from the command line, the answer is yes: it will launch in HiDPI and render text in high resolution. Things rendered using Graphics2D will render in high resolution mode. (So if you render a line 0.5 AWT pixels thick and place it at 0.25/0.75 off an AWT pixel, it will render a single "retinal pixel" thick.) Likewise, rendering an image at half-resolution will render it at "retinal" resolution.

So instead of just g.drawImage(image, x, y, observer) you'd need to do:

g.drawImage(image, x, y,
    image.getWidth(observer)/2,
    image.getHeight(observer)/2, observer);

(Unless you have an odd width/height, in which case you should probably use Graphics2D and just scale(0.5, 0.5) to render a retinal image.)

If you use JavaApplicationStub, then you need the answer provided by Matt Solnit, otherwise it will launch in the "scaled" mode. (Under Mountain Lion, there are added hoops to jump through related to Gatekeeper, but that's a different question.)

Note that this answer applies to both Mountain Lion and the Apple-provided version of Java for it (Java 1.6.0_33). It might be different under Oracle's Java 7 for Mac OS X, and it may not work the same way under Lion.