Link to home
Start Free TrialLog in
Avatar of joey9394
joey9394

asked on

System font for applet

I tried to use Verdana font, Font("Verdana", Font.PLAIN, 14), in my applet, but the applet displayed in Arial font.

I tried to use other fonts like Serif, Courier and it worked.

Is it because the applet can't access the system font?  Or how can I use Verdana font in my applet?

Thanks.

Joey
Avatar of sumit_only
sumit_only

Make sure u do hv that font in your system. Other than that it should not really be a problem. TO double check (for knowing all the fonts in your system) use getAllFonts() method inside GraphicsEnvironment class. This method returns an array of all the system fonts available on your machine.
Hope this helps
Sumit
ASKER CERTIFIED SOLUTION
Avatar of heyhey_
heyhey_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of joey9394

ASKER

Thanks for the quick response.

I run this code locally
 Font[] s = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
    for(int i = 0; i < s.length; i++)
      System.out.println(s[i]);

and saw Verdana in the printout:
java.awt.Font[family=Verdana,name=Verdana,style=plain,size=1]
java.awt.Font[family=Verdana,name=Verdana Cursiva,style=plain,size=1]
java.awt.Font[family=Verdana,name=Verdana Negreta,style=plain,size=1]
java.awt.Font[family=Verdana,name=Verdana Negreta cursiva,style=plain,size=1]

However, I tried to run the same code inside the applet, and got the following error from the browser's Java console:
java.lang.ClassNotFoundException: java.awt.GraphicsEnvironment
      at com/ms/vm/loader/URLClassLoader.loadClass (URLClassLoader.java)
      at java/lang/ClassLoader.loadClassInternal (ClassLoader.java)
      at AltraTicker.init (AltraTicker.java)
      at com/ms/applet/AppletPanel.securedCall0 (AppletPanel.java)
      at com/ms/applet/AppletPanel.securedCall (AppletPanel.java)
      at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
      at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
      at com/ms/applet/AppletPanel.run (AppletPanel.java)
      at java/lang/Thread.run (Thread.java)

Any idea?


That means the browser u hv has JVM that does not support GraphicsEnvironment. Because u'r error shows class com.ms. .... means that u r trying this on IE. Try Toolkit as suggested by heyhey.
Sumit
Thanks.  I changed to use the toolkit class and got the following fonts

Dialog
Helvetica
TimesRoman
Courier
DialogInput
ZapfDingbats

Does it mean I can't use any OS system font, such as Verdana?
No u cannot. This means that u can only use these fonts. This was already suggested by heyhey.
Sumit
Thanks a lot!