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!)
J
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)");
frame.setLayout(null);
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);
frame.add(label1);
JPanel blackBox = new JPanel();
blackBox.setBounds(100, d1.height+40, 2*res, 2*res);
blackBox.setBackground(Color.BLACK);
frame.add(blackBox);
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.add(label2);
frame.setSize(d2.width + 100, d1.height + 2*res + d2.height + 100);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}