Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4262130

JLabel having last few pixels cut off when italic font used

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.2
    • client-libs



      Name: krT82822 Date: 08/12/99


      8/12/99 kevin.ryan@eng -- definitely looks like a problem. Previous, similar reports closed (e.g., for lack of a pack()). Filing new bug.

      This seems similar to the problem with menubar items mentioned in bugs 4117502 and 4046147, except that this still happens and it is dealing with JLabels.
      If I create a JLabel, and use setFont() to set its font to one that has Font.ITALIC set, it seems that the JLabel doesn't properly size its width to handle the extra space needed by the italicized font. This is most noticeable with a letter such as an uppercase N in a serif font, and it happens both on the display screen and in printing (it is worse with printing, but noticeable on the screen).
      Below is a short program (thanks to Gordon Tranter at KL Group for the code sample) that will reproduce the problem, and show the effect. It creates two labels, both saying "Hello WorldN" in italics. The second label adds a space at the end, which causes the JLabel to create a little more space. When run (at least on WinNT4.0), you can plainly see the top right part of the N gets a few pixels lobbed off.
      The code:
      import java.awt.*;
      import javax.swing.*;

      public class JLabelFontClip extends JFrame
      {
      JLabel badLabel, goodLabel;
      JPanel panel;
      JButton button;

      public JLabelFontClip() {

         badLabel = new JLabel("Hello WorldN");
         badLabel.setFont(new Font("Serif",Font.BOLD + Font.ITALIC, 24));
         badLabel.setHorizontalAlignment(JLabel.LEFT);

         goodLabel = new JLabel("Hello WorldN ");
         goodLabel.setFont(new Font("Serif",Font.BOLD + Font.ITALIC, 24));
         goodLabel.setHorizontalAlignment(JLabel.LEFT);

         getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
         getContentPane().add(badLabel);
         getContentPane().add(goodLabel);
         
         pack();
         setVisible(true);
      }

      public static void main(java.lang.String[] args) {
         new JLabelFontClip();
      }
      }

      Info on my system (where I can reproduce it any time):
      ------------------------------------------------------
      Windows NT 4.0, Service Pack 4
      JDK 1.2.2
      java -version returns:
      java version "1.2.2"
      HotSpot VM (1.0fcs, mixed mode, build E)
      java -fullversion returns:
      java full version "JDK-1.2.2-W"
      (Review ID: 93845)
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: