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 9009531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:13:19+00:00 2026-06-16T02:13:19+00:00

I am trying to display a custom font within a JLabel, but when I

  • 0

I am trying to display a custom font within a JLabel, but when I create it, it displays as very tiny text. I cant even tell if it is using the font that I specified, because the text is so small. Here is the font that I used. So what am I doing that is causing the font to be so small?

package sscce;

import java.awt.Font;
import java.awt.FontFormatException;
import java.io.File;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Main extends JFrame{

    public Main(){
        this.setSize(300, 300);
        this.setResizable(false);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


        GameFont fnt = new GameFont("/home/ryan/Documents/Java/Space Shooters/src/media/fonts/future.ttf", 20);
        Label lbl = fnt.createText("Level 1 asdf sadf saf saf sf ");

        this.add(lbl);
    }

    public static void main(String[] args){
        Main run = new Main();
    }

    public class GameFont{

        protected Font font;

        public GameFont(String filename, int fontSize){
            try{
                File fontFile = new File(filename);
                font = Font.createFont(Font.TRUETYPE_FONT, fontFile);
                font.deriveFont(fontSize);
            }catch(FontFormatException | IOException e){
            }
        }

        public Label createText(String text){
            Label lbl = new Label(font);
            lbl.setText(text);
            return lbl;
        }
    }

    public class Label extends JLabel{

        public Label(Font font){
            this.setFont(font);
        }
    }
}
  • 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-06-16T02:13:20+00:00Added an answer on June 16, 2026 at 2:13 am

    Please look again at the Font API, deriveFont(…) method. You want to pass in a float, not an int for the size, since if an int parameter is passed in, the method will expect this to mean to set a Font’s style (bold, italics, underlined), not its size. You also need to use the Font returned by the deriveFont(...) method.

    So change this:

       public GameFont(String filename, int fontSize){
            try{
                File fontFile = new File(filename);
                font = Font.createFont(Font.TRUETYPE_FONT, fontFile);
                font.deriveFont(fontSize);
            }catch(FontFormatException | IOException e){
            }
        }
    

    to this:

       public GameFont(String filename, float fontSize){
            try{
                File fontFile = new File(filename);
                font = Font.createFont(Font.TRUETYPE_FONT, fontFile);
                font = font.deriveFont(fontSize);
            }catch(FontFormatException | IOException e){ 
               e.printStackTrace(); // ****
            }
        }
    

    Also, never ever ignore exceptions like you’re doing!

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

Sidebar

Related Questions

I am trying to display arabic text with custom font. my code is as
I am trying to display a custom sheet in my application, but I think
I'm trying to style a custom menu within drupal. I've sucessfully styled to display
I'm trying to get IE9 to display a custom font. Should be easy... researched
just created an UITableView, trying to display some custom data from an array, but
I am trying to display the parsed xml data in custom listview but the
The webpage where I'm trying to get the custom font Duke-Fill to display is
I am trying to display a custom TableView on a UIViewController but am getting
I'm trying to display a custom ListView that has a thumbnail image and text
(Magento Version 1.6) I'm trying to display a custom category attribute I created to

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.