Sorand
Sorand

Reputation: 115

Antialiasing of text in Swing components , using JDK 7

please tell me how to enable antialiasing for text in Swing components (using JDK 7), not overriding method paintComponent() parent class. To read about this topic , which says that for this method is used

putClientProperty(
     com.sun.java.swing.SwingUtilities2.aa_text_property_key, Boolean.TRUE);

requires a package com.sun.java.swing.SwingUtilities2, which is absent in the JDK older 5th version. Do not want to include in the project the outdated methods and libraries, could you please tell me what methods are used now for smoothing text of the components(similar putClientProperty()).

PLEASE DON'T WRITE about the use methods

g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
     RenderingHints.VALUE_ANTIALIAS_On);
//or 

g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIAsing,
     RenderingHints.VALUE_TEXT_ANTIALias_on);

because they do NOT WORK EVEN IF YOU OVERRIDE the paintComponent() parent class, the example below:

 JButton button = new JButton("Button X O") {

    @Override
    public void paintComponent(Graphics g){
         Graphics2D g2d = (Graphics2D) g;
         //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
               //RenderingHints.VALUE_ANTIALIAS_On);
         g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, 
               RenderingHints.VALUE_TEXT_ANTIALIASING_ON);
         super.paintComponent(g2d);
         g2d.dispose();
    }
 };

It's not Work! Please, help.

Upvotes: 0

Views: 1660

Answers (1)

Peter Walser
Peter Walser

Reputation: 15706

Global settings using system properties:

  System.setProperty("awt.useSystemAAFontSettings","on");
  System.setProperty("swing.aatext", "true");

By the way, the override should work if you override paint(Graphics g) (which then paints the component, border and children) in the root container instead of paintComponent(Graphics g).

Upvotes: 3

Related Questions