Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 537259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:54:29+00:00 2026-05-13T09:54:29+00:00

I have been attempting to enhance my GUI system written in Java to use

  • 0

I have been attempting to enhance my GUI system written in Java to use subpixel antialiasing and have been successful, except for two remaining anomalies. This is a follow on to my other question from a few weeks ago.

The first problem is that setting rendering hints KEY_ANTIALIASING to VALUE_ANTIALIAS_ON causes KEY_TEXT_ANTIALIASING to be ignored when it is set to an LCD (subpixel) AA value. Can anyone shed some light on this? Currently I am forced to VALUE_ANTIALIAS_OFF before rendering text and turn it back on after rendering text (so that other painting, like circles, etc, is AA’d). This problem is proven by the self-contained test program below.

The second problem is that I can find no way to query the underlying O/S setting for AA, so I have to do a rather kludgey workaround, which is to create a Swing JLabel, get it’s FontMetrics, get it’s FontRenderContext and then get the AA hint from that. Apart from involving Swing in a program that otherwise makes absolutely no use of Swing, it will not work on a device running any J2ME JVM. Can anyone suggest a better way to do this? It’s OK if it requires J5 or J6, since the current kludge already requires J6 (but needing only J4 would be best). I have already tried every default setting and using an AWT component instead of JLabel.


Test Program

This program verifies that for subpixel AA to work, the general AA setting must first be disabled. (PS: I write to a back-buffer because my underlying GUI does, and I wanted to test in an equivalent context).

import java.awt.*;
import java.awt.event.*;

public class AwtTestFrame1b extends Panel {

private final Font                      font=new Font(Font.SANS_SERIF, Font.PLAIN, 16);
private final int                       line=25;

AwtTestFrame1b() {
    setBackground(SystemColor.control);
    }

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D)g;

    int                                 py=0;

    py=paintText(g2d,py,null                                        ,false);
    py=paintText(g2d,py,null                                        ,true );
    py+=line;

    py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_OFF     ,false);
    py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT ,false);
    py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_ON      ,false);
    py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_GASP    ,false);
    py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB,false);
    py+=line;

    py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_OFF     ,true );
    py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT ,true );
    py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_ON      ,true );
    py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_GASP    ,true );
    py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB,true );
    py+=line;
    }

private int paintText(Graphics2D g2d, int py, Object val, boolean aa) {
    Graphics2D                          dgc=g2d;
    char[]                              txt=("The quick brown fox jumped over the lazy dog ("+val+", General AA: "+aa+")").toCharArray();
    Image                               img=null;

    GraphicsConfiguration cfg=getGraphicsConfiguration();
    img=cfg.createCompatibleImage(getWidth(),line);
    dgc=(Graphics2D)img.getGraphics();
    dgc.setColor(getBackground());
    dgc.fillRect(0,0,getWidth(),line);
    dgc.setColor(g2d.getColor());

    if(aa       ) { dgc.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON ); }
    else          { dgc.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF); }
    if(val!=null) { dgc.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,val); }
    dgc.setFont(font);

    dgc.drawChars(txt,0,txt.length,10,line-5);
    g2d.drawImage(img,  0,py,  null);

    dgc.dispose();
    img.flush();

    return (py+line);
    }

public static void main(String[] args) {
    Frame                               wnd=new Frame("AWT Antialiased Text Sample");

    wnd.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
            }
        });
    wnd.add(new AwtTestFrame1b());
    wnd.setSize(new Dimension(1000, 600));
    wnd.setVisible(true);
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:54:30+00:00Added an answer on May 13, 2026 at 9:54 am

    Are the AWT Desktop Properties of any help? In particular, “awt.font.desktophints” – these contain the AA hints that the native components use, but can be applied to any Graphics2D you want.

    Just a shot in the dark, having recently read through the AA section in Filthy Rich Clients.

    Use would look something like this:

    String str = "A quick brown fox jumps over the lazy dog";
    Toolkit tk = Toolkit.getDefaultToolkit();
    Map desktopHints = (Map)(tk.getDesktopProperty("awt.font.desktophints"));
    Graphics2D g2d = (Graphics2D)g;
    
    if(desktopHints != null) {
        g2d.addRenderingHints(desktopHints);
    }
    
    g2d.drawString(str, someX, someY);
    

    I was able to get the same results (using your example class and drawChars and drawImage, just typed drawString for simplicity) as the LCD HRGB mode using these hints and no other calls on my machine.

    I’m not sure what release of Java this requires, if it’s what you’re looking for…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 318k
  • Answers 318k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer While this is not used, the method makes frequent use… May 13, 2026 at 11:50 pm
  • Editorial Team
    Editorial Team added an answer SDCC doesn't support assignment and returning structs yet (if their… May 13, 2026 at 11:50 pm
  • Editorial Team
    Editorial Team added an answer Well I found the answer with a little more digging.… May 13, 2026 at 11:50 pm

Related Questions

I get errors like this when attempting to run unit tests under App Engine
I have an existing application that is written in C++ for Windows. This application
I have been attempting to write some routines to read RSS and ATOM feeds
I have been attempting to handle the KeyDown event of a UserControl (page) in
I have been attempting to have a object that I can use across multiple

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.