🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #555

Re: How to set which fonts to use when the default is missing

#555
From: Katerina K.
Date: Fri, 04 Mar 2005 14:05
44 lines
2153 bytes
I just found a way to do this. I am not sure if it is the best one, but it 
works. If anyone has a better suggestion, I will be glad to read it!

public static boolean checkIfRequiredFontIsInstalled( Font usedFont )
{
  try
  {
    String[] fontArray = 
GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
    int numOfFonts = fontArray.length;
    for ( int i = 0; i < numOfFonts; i++ )
    {
      if ( fontArray[ i ].equals( usedFont.getFamily() ) )
      {
       // System.out.println( "I found it!Font name is " + 
usedFont.getFontName() );
        return true;
      }
    }
    return false; // used font not found
  }
  catch ( Exception ex )
  {
    return false;
  }
}


Therefore, now I can do this:
...
    Font usedFont = new java.awt.Font("myOwnFont", 1, 18);
    boolean usedFontExists = checkIfRequiredFontIsInstalled( usedFont );
    if( usedFontExists )
    {
      this.setFont( usedFont );
    }
    else
    {
        this.setFont(new java.awt.Font("Dialog", 1, 26));
    }
...

Katerina 
Technical Details
Message-ID: <42286b35$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!newspeer.monmouth.com!newsfeed.icl.net!newsfeed.fjserv.net!news.tele.dk!news.tele.dk!small.news.tele.dk!news-fra1.dfn.de!newsfeed.ision.net!ision!news.belwue.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <42283751$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,2987ed43b256ce67
X-Google-Attributes: gidf74b3,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Katerina K." <scorpio_gemini@hotmail.com>
Newsgroups: borland.public.jbuilder.java.language
References: <42283751$1@newsgroups.borland.com>
Subject: Re: How to set which fonts to use when the default is missing
Date: Fri, 4 Mar 2005 15:05:33 +0100
Lines: 46
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: 129.132.68.93
Message-ID: <42286b35$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1109945141 129.132.68.93 (4 Mar 2005 06:05:41 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!newspeer.monmouth.com!newsfeed.icl.net!newsfeed.fjserv.net!news.tele.dk!news.tele.dk!small.news.tele.dk!news-fra1.dfn.de!newsfeed.ision.net!ision!news.belwue.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail