Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux, windows_xp

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.6.0-rc"
        Java(TM) SE Runtime Environment (build 1.6.0-rc-b96)
        Java HotSpot(TM) Client VM (build 1.6.0-rc-b96, mixed mode, sharing)

        ADDITIONAL OS VERSION INFORMATION :
        Linux io 2.6.11.4-21.11-smp #1 SMP Thu Feb 2 20:54:26 UTC 2006 i686 i686 i386 GNU/Linux

        A DESCRIPTION OF THE PROBLEM :
        The text in a JLabel is truncated when HorizontalAlignment == SwingConstants.TRAILING, a PLAIN style font of the default size is used and the text ends with 'v' or 'y'.


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the program attached to this report and have a look at the end of the lines. You can see that all labels are fully visible except for the lines ending with 'v' or 'y'. I have the impression that the dimensions for the 'v' and 'y' characters in the PLAIN font are wrong. If you type two 'v' or two 'y' characters in a JTextField you can see (using xmag or kmag) that the 'v' and 'y' characters share one pixel in the default font size.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The text of all labels should be fully visible.
        ACTUAL -
        The text of the label is truncated if it ends with 'v' or 'y'.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.awt.*;
        import javax.swing.*;

        public class TruncatedLabel {

            public TruncatedLabel() {
            }

            private static void addLabels(JPanel panel) {
                JLabel label = new JLabel();
                Font font = label.getFont().deriveFont(Font.PLAIN);
                for (char c = 'a'; c <= 'z'; c++) {
                    if (c == 'v' || c == 'y') {
                        label = new JLabel("This label is wrong: " + c);
                    } else {
                        label = new JLabel("This label is correct: " + c);
                    }
                    label.setFont(font);
                    label.setHorizontalAlignment(SwingConstants.TRAILING);
                    panel.add(label);
                }
            }

            private static void createAndShowGUI() {
                JLabel label;
                JPanel panel = new JPanel(new GridLayout(26, 1));
                panel.setBorder(BorderFactory.createEmptyBorder(12, 12, 11, 11));

                addLabels(panel);

                JFrame frame = new JFrame("TruncatedLabel");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.add(panel);
                frame.pack();
                frame.setVisible(true);
            }

            public static void main(String[] args) {
                javax.swing.SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        createAndShowGUI();
                    }
                });
            }
        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Use bold font style for labels.
        There is a problem for left text side too. It is caused by a bug in the SwingUtilities2.getLeftSideBearing() method, which leads to text clipping for any swing labels. See screenshots and a test case in the attachment. Now the left bearing is calculated only for the 'W' character!

        Testing strategy:
           1. Run the TextClippingDemo
           2. Select a font and its size
           3. You'll see a frame with clipped strings (if there is any). Each line will begin with a clipped character and it will be followed by the same unclipped one and by the value of the left side bearing (how many pixels were clipped).
        Here is the modified version of test, which shows the problem on Windows and Linux:

        import java.awt.*;
        import javax.swing.*;

        public class TruncatedLabel {

            public TruncatedLabel() {
            }

            private static void addLabels(JPanel panel) {
                JLabel label = new JLabel();
                Font font = Font.decode("Lucida Bright Italic-12");
                for (char c = 'A'; c <= 'Z'; c++) {
                    label = new JLabel("The letter is " + c);
                    label.setFont(font);
                    label.setHorizontalAlignment(SwingConstants.TRAILING);
                    panel.add(label);
                }
            }

            private static void createAndShowGUI() {
                JLabel label;
                JPanel panel = new JPanel(new GridLayout(26, 1));
                panel.setBorder(BorderFactory.createEmptyBorder(12, 12, 11, 11));

                addLabels(panel);

                JFrame frame = new JFrame("TruncatedLabel");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.add(panel);
                frame.pack();
                frame.setVisible(true);
            }

            public static void main(String[] args) {
                javax.swing.SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        createAndShowGUI();
                    }
                });
            }
        }

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  alexp Alexander Potochkin (Inactive)
                  Reporter:
                  ndcosta Nelson Dcosta
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  1 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: