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

Text length in anti-aliased swing components is wrong

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.0
    • client-libs
    • 2d
    • x86
    • windows_nt



      Name: rl66838 Date: 07/12/2000


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      On Windows, anti-aliased JLabel and JButton are not useable because
      their size is initialized with the length of not a-a text, which
      is different of the length of a-a text (a ... appears).

      Similarly, selecting text in a a-a JTextComponent shows a colored
      background that does not cover the proper range of selected text.

      This is somewhat related to bug 4233886, but this one is closed.

      Sample code :

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

      class AA extends JFrame {
        public static void main(String[] s) {
          new AA();
        }
        AA() {
          getContentPane().setLayout(new FlowLayout());
          getContentPane().add(new AAText("a long long long line of text"));
          getContentPane().add(new AAButton("button"));
          pack();
          show();
        }
      }

      class AAText extends JTextArea {
        AAText(String s) {
          super(s, 4, 40);
        }
        public void paintComponent(Graphics g) {
           ((Graphics2D)g).setRenderingHint
            (RenderingHints.KEY_ANTIALIASING,
             RenderingHints.VALUE_ANTIALIAS_ON);
          super.paintComponent(g);
        }
      }

      class AAButton extends JButton {
        AAButton(String s) {
          super(s);
        }
        public void paintComponent(Graphics g) {
           ((Graphics2D)g).setRenderingHint
            (RenderingHints.KEY_ANTIALIASING,
             RenderingHints.VALUE_ANTIALIAS_ON);
          super.paintComponent(g);
        }
      }
      (Review ID: 107116)
      ======================================================================

            Unassigned Unassigned
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: