Search code examples
javatruetype

Java TrueTypeFont


I'd like to use the TrueTypeFont class from sun.font.TrueTypeFont package in my applet, but Eclipse keeps complaining about the constructor not being visible:

import sun.font.TrueTypeFont;
.
.
.    
new TrueTypeFont("a", new Object(), 1, false);

yields:

    - The constructor TrueTypeFont(String, Object, int, boolean) is not visible

Is there a way to fix this? Is there a way to cast Font class to TrueTypeFont? I need to get data provided by methods of TrueTypeFont.


Solution

  • You have multiple problems there:

    • sun.font.TrueTypeFont is an implementation class that you shouldn't be playing around with.
    • It's constructor is "package private" (default access) which means you can't access it from another package (which is what Eclipse happens to be telling you).
    • Even if you could access it, an [untrusted] applet cannot access sun.* classes (controlled by the package.access security property).