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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:22:50+00:00 2026-05-20T09:22:50+00:00

I was wondering if there is a way for extending Font class in a

  • 0

I was wondering if there is a way for extending Font class in a manner that I could return my own Font class by createFont and deriveFont methods. I mean something like this…

public class MyFont extends Font {

    // Constructor
    public MyFont (...) {
        super(...);
    }

    // createFont method
    public static MyFont createFont (...) {
        // body
    }

    // deriveFont method
    public static MyFont deriveFont (...) {
        // body
    }
}

I’ve tryied but I could not retrieve any font, and when doing it the font I got was the default one (I mean “Dialog”).

The reason for doing is is to minimize the impact produced by an eventual change in later Java distributions of its VM.

This is the code summoned above:

MyFont onePoint=MyFont.createFont(MyFont.TRUETYPE_FONT,fontStream, size); 

Then in MyFont, I coded:

public static MyFont createFont (int i, InputStream io, int size) throws FontFormatException, IOException { 
    Font font = Font.createFont(i, io); 
    MyFont kfont = new
        MyFont(font.getName(),font.getStyle(),font.getSize()); 
    return kfont;
}
  • 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-20T09:22:51+00:00Added an answer on May 20, 2026 at 9:22 am

    0th. What if someone wants to pass generic Font to your code, and you require argument being instance of MyFont. Does it make any practical sense? You try to use inheritance to adjust some lifecycle protocols (object creation in this case) which does not fit well into Java OO-paradigm. Use a factory method/prototype instead.

    1st. createFont() is not overridable as it’s static. You may provide your own version in your class, but using the same method name may confuse other users of your code (and, later on, you too).

    2nd. while providing some shortcuts to createFont() and possible new versions of deriveFont() you don’t avoid linking against the API you want to control changes of, so you’d have to recode/recompile anyway, given java implementations change. Proper dependency avoidance involves some reflection and String-coded class names with catching lots of ClassNotFound exceptions and other whatnot which may happen on an API change. You don’t want that. Period.

    3rd. just relax, really, this code is quite stable and chances your app gets outdated and rewritten from scratch are much greater than anyone even deprecates those methods, leave alone removing them. this is well beyond the end of world in 2012 (or any other more or less relevant date closer than heat death of the universe).

    To wrap it up, just add couple of easily distinguishable static shortcuts: MyFonts.create() chained to the Font.creatFont(), and another MyFonts.derive(Font font, otherargs) chained to font.derive(otherArgs). Keep it simple, dude, and seal the MyFonts() constructor, to indicate this is a factory/utility class.

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

Sidebar

Related Questions

I was wondering is there a way in PHP that you could tell where
I wondering is there any way to set restrictions on template class? Specify that
just wondering is there any way that I can return one value from my
I was wondering is there way i could start my application (that stays in
I was wondering is there a way that I could have my code tap
I am wondering is there any way we can test the font size/color of
Wondering if there is any way to get the lambda expressions that result from
I'm wondering if there's a way to list all custom taxonomies that are siblings
I'm wondering is there a way to overwrite Hashtable (or Dictionary) class so it
I'm wondering whether there's a way to extend the BaseDaoImpl class of ORMLite on

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.