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

  • SEARCH
  • Home
  • 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 6374609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:30:34+00:00 2026-05-25T01:30:34+00:00

I’m trying to create a SWING application using Java 1.6 and I have a

  • 0

I’m trying to create a SWING application using Java 1.6 and I have a JLabel that uses a custom font from a .ttf file.

I thought 1.6 had anti-aliasing on by default, but my text is pretty pixelized.

Here’s a code sample and an image showing the result:

package aceprobowler.test;

import java.awt.Color;
import java.awt.Font;
import java.io.InputStream;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import aceprobowler.options.OptionsValues;

public class TestAntialiasedText extends JFrame
{
    private static final long serialVersionUID = 2411330284507353990L;

    public TestAntialiasedText(String title)
    {
        super(title);
        setSize(800,200);
        
        Font titleFont = null;
        
        try
        {
            InputStream is = OptionsValues.class.getResourceAsStream("fonts//KOMIKAX_.ttf");
            titleFont = Font.createFont(Font.TRUETYPE_FONT, is).deriveFont(Font.PLAIN, 60);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
            System.err.println("font not loaded.  Using serif font.");
            titleFont = new Font("serif", Font.PLAIN, 24);
        }
        
        JPanel panelWithText = new JPanel();
        JLabel labelWithText = new JLabel("This is a test");
        
        labelWithText.setFont(titleFont);
        
        labelWithText.setBackground(Color.BLACK);
        labelWithText.setForeground(Color.WHITE);
        labelWithText.setOpaque(true);
        
        panelWithText.add(labelWithText);
        add(panelWithText);
    }
    
    public static void main(String[] args)
    {
        SwingUtilities.invokeLater(new Runnable()
        {
            public void run()
            {
                new TestAntialiasedText("Testing text anti-alias").setVisible(true);
            }
        });
    }
}

Mostly apparent on the "T"s and on the "A"
Not anti-aliased text

I tried creating an inner class overriding paintComponent(Graphics g) and using

Graphics2D g2 = (Graphics2D)g; 
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)

But it doesn’t work. Can anyone help me out with this? I can’t find any information on the internet about this since Javaj 1.6 is supposed to make everything SWING related Anti-aliased by default.

Thanks in advance!

  • 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-25T01:30:34+00:00Added an answer on May 25, 2026 at 1:30 am

    When you override the paintComponent method of the JLabel instance, I believe that you’ll need to use the following:

    • Graphics.drawString(String str, int x, int y)
    • RenderingHints.KEY_TEXT_ANTIALIASING

    For an example, see:

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I have thousands of HTML files to process using Groovy/Java and I need to
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.