JLabel preferred size incorrect on retina displays when other than default font size is used

Robert Krüger krueger at lesspain.de
Tue Apr 30 01:13:22 PDT 2013


when running the following code on a retina display and on a non-retina,
you will see the problem:

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.WindowConstants;

public class JLabelDemo {

    public static void main(String[] args) {

        JFrame frame = new JFrame("JLabel Demo");
        Container contentPane = frame.getContentPane();
        contentPane.setLayout(new FlowLayout());
        final JLabel label = new JLabel(
                "This is a monstrous mmmmmega label text which will not
        label.setFont(new Font(label.getFont().getName(),
label.getFont().getStyle(), 11));



On retina the text will be cut off because the preferred width calculation
appears to be wrong. When connecting a retina MBP to a non-retina monitor
it is also possible to drag the frame between the two windows and see how
the text is cut off on one and isn't on the other.

This happens with OpenJDK 8 from recent source (a week ago) and doesn't
with JDK7u21 (which does not have hires graphics support). Note that it
also happens with Apple's JDK6.

Is this a known issue or should I submit a bug report?

More information about the macosx-port-dev mailing list