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

rendering hints for anti-aliasing doesn't work for AWT components

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P2 P2
    • None
    • 1.4.2_10
    • client-libs
    • 2d
    • x86
    • windows

      This is from a customer escalation esc# 1-17241052 case# 65028921.
      CU is on JDK 1.4.2_10
      The following test case demonstrated that setting anti-aliasing hints works
      for Swing but not AWT components.

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

      public class aafont {

        private static MyJTextField jTextField1 = new MyJTextField();
        private static MyTextField TextField1 = new MyTextField();


        public static void main(String[] args) {
      jbInit();
        }

        private static void jbInit()
        {

          jTextField1.setText("WWW SWING - TextField");
          jTextField1.setBounds(new Rectangle(220, 70, 175, 30));
          jTextField1.setFont(new Font("Arial", 0, 24));

          TextField1.setText("WWW AWT - TextField");
          TextField1.setBounds(new Rectangle(10, 70, 175, 30));
          TextField1.setFont(new Font("Arial", 0, 24));


          JFrame frame = new JFrame("Font");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          JPanel panel = new JPanel();
          frame.getContentPane().add(panel);

          JLabel label = new JLabel("Hello World");
          panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
          panel.add(jTextField1, null);
          panel.add(TextField1, null);

          frame.setLocation(100,100);
          frame.validate();
          frame.pack();
          frame.setVisible(true);
        }
      }

      class MyTextField extends TextField {
          public void paint(Graphics g) {
      Graphics2D g2d = (Graphics2D)g;
      g2d.setRenderingHint(
                   RenderingHints.KEY_TEXT_ANTIALIASING,
                   RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
      super.paint(g);
      }
        }


      class MyJTextField extends JTextField {
          public void paintComponent(Graphics g) {
      Graphics2D g2d = (Graphics2D)g;
      g2d.setRenderingHint(
                  RenderingHints.KEY_TEXT_ANTIALIASING,
                  RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
      super.paintComponent(g);
          }
      }

            kbalasubsunw Kannan Balasubramanian (Inactive)
            lkchow Lawrence Chow
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: