Java Reference
In-Depth Information
return
return new
new Dimension ( 250 , 100 );
}
@Override
public
public Dimension getPreferredSize () {
return
return new
new Dimension ( 320 , 150 );
}
}
See Also
I have not discussed how to scale, rotate, or otherwise transmogrify an image using the
AffineTransform class in Java 2D graphics because such topics are beyond the scope of
this topic. Consult the previously mentioned Java 2D Graphics .
Drawing Text with an Application Font
Problem
You want to provide a font with your application but do not want to require users to install it
as a “system font” on all platforms.
Solution
Use Font.createFont(…) , which returns a scalable Font object, and scale it with de-
riveFont(int nPoints) .
Discussion
Java includes the static method Font.createFont() , which allows you to have a “private”
font that can be used in your application without having it installed using the operating sys-
tem's font mechanism. Users can then use your application and its custom font without hav-
ing to have “root” or “administration” privileges on systems that require this in order to in-
stall fonts.
The createFont() method requires two arguments. The first is an int , which must be the
public static field Font.TRUETYPE_FONT , and the second is an InputStream (see Reading/
Writing Binary Data ) that is open for reading the binary file. As you can infer from the re-
Search WWH ::




Custom Search