Although layout managers usually scale text properly, with the spread of "retina" Macs with screen resolutions over 200 d.p.i. we can't just keep ignoring pixel size for grahics or animation.
Toolbox has a method for getting the screen resolution, but I don't have access to enough varied machines to see how accurate that is in real life.
Can you please help me by running the following little program on your machine and posting the results? It should show a 2 inch (5 cm) black box, and I would really like to know:

  • actual size of box as measured by a ruler
  • operating system
  • monitor type

Thank you very much for your help

(ps, please don't use this little hack as an example of Java coding practice!)

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class ScreenRes {

    public static void main(String[] args) {
        int res = Toolkit.getDefaultToolkit().getScreenResolution();
        JFrame frame = new JFrame("(close window to exit)");

        JLabel label1 = new JLabel("Reported screen resolution is " + res + " d.p.i.");
        Dimension d1 = label1.getPreferredSize();
        label1.setBounds(50, 0, d1.width+20, d1.height+20);

        JPanel blackBox = new JPanel();
        blackBox.setBounds(100, d1.height+40, 2*res, 2*res);

        JLabel label2 = new JLabel("The black box should be 2 inches (5.08 cm) square");
        Dimension d2 = label2.getPreferredSize();
        label2.setBounds(50, d1.height+40 + 2*res, d2.width+20, d2.height+20);

        frame.setSize(d2.width + 100, d1.height + 2*res + d2.height + 100);

Windows XP
Samsung SyncMaster 923NW

screen resolution - 96 d.p.i

on my desktop:

Windows 8
Samsung flatscreen
width of the black square: 5.4 cm

reported screen resolution: 96 d.p.i. (same as it was on the laptop)

I will try it out tonight on my laptop and both screens at home, will get back with results

This article has been dead for over six months. Start a new discussion instead.