FOLLOW ME Twitter Facebook Вконтакте LinkedIn RSS Feed
Browsing articles tagged with " AWT"

Retina support in Oracle JDK 1.7.0_40 and above

Jun 23, 2013
Category: Java

Hi everyone!

A few days ago I installed Oracle JDK (version 1.7.0_40) built especially for early access purposes. So, it’s not the final release. The build contains tons of bug fixes and backports from JDK 8 for AWT/Swing and that was the main point why I started to play with it. As you might have heard, Retina support was one of the major issues in all 1.7.* releases. I’d say there was no Retina support before the build 1.7.0_40. I’m going to show you some differences of Retina support in Apple and Oracle JDKs.
 

1. isRetina() method

That’s funny, but there is no public API for it in Oracle JDK 7. Here is how we (IntelliJ IDEA team) do it under Apple JDK:

class IsRetina {
  public static final boolean isRetina = isRetina();

  private static boolean isRetina() {
    try {
      final boolean[] isRetina = new boolean[1];
      new apple.awt.CImage.HiDPIScaledImage(1,1,BufferedImage.TYPE_INT_ARGB) {
        @Override
        public void drawIntoImage(BufferedImage image, float v) {
          isRetina[0] = v > 1;
        }
      };
      return isRetina[0];
    } catch (Throwable e) { 
      e.printStackTrace();
      return false;
    }
  }
}

Continue reading »