1package com.jogamp.opengl.test.junit.jogl.awt;
3import java.awt.BorderLayout;
5import java.awt.Dimension;
6import java.awt.Graphics;
7import java.awt.Graphics2D;
9import java.awt.image.BufferedImage;
10import java.lang.reflect.InvocationTargetException;
12import javax.swing.JCheckBox;
13import javax.swing.JComponent;
14import javax.swing.JFrame;
15import javax.swing.SwingUtilities;
22 static final int width = 200;
23 static final int height = 100;
25 public static void main(
final String[] args)
throws InterruptedException, InvocationTargetException {
26 final JFrame frame =
new JFrame();
28 SwingUtilities.invokeLater(
new Runnable() {
31 final Image image1 = getImage(getCheckBox(
"High-DPI (no)",
false), width, height, 1);
32 final Image image2 = getImage(getCheckBox(
"High-DPI (yes)",
true), width, height, 2);
33 System.err.println(
"Image1: "+image1);
34 System.err.println(
"Image2: "+image2);
36 @SuppressWarnings(
"serial")
37 final Canvas canvas =
new Canvas() {
39 public void paint(
final Graphics g) {
41 g.drawImage(image1, 0, 0, width, height,
this);
42 g.drawImage(image2, 0, height + 5, width, height,
this);
45 frame.getContentPane().add(getCheckBox(
"High-DPI (ref)",
false), BorderLayout.NORTH);
46 frame.getContentPane().add(canvas, BorderLayout.CENTER);
48 frame.setBounds((1440-400)/2, 100, 400, 400);
50 frame.setVisible(
true);
55 static JCheckBox getCheckBox(
final String text,
final boolean selected) {
56 final JCheckBox checkBox =
new JCheckBox(text);
57 checkBox.setSelected(selected);
58 checkBox.setSize(
new Dimension(width, height));
62 static Image getImage(
final JComponent component,
final int width,
final int height,
final int scale) {
63 final BufferedImage image =
new BufferedImage(width*scale, height*scale, BufferedImage.TYPE_INT_ARGB);
64 final Graphics g = image.getGraphics();
65 ((Graphics2D) g).scale(scale, scale);
Manual test for BufferedImage behavior w/ OSX HiDPI pixel scale usage.
static void main(final String[] args)