Returns the
Font
that the
str
argument describes.
To ensure that this method returns the desired Font,
format the
str
parameter in
one of these ways
- fontname-style-pointsize
- fontname-pointsize
- fontname-style
- fontname
- fontname style pointsize
- fontname pointsize
- fontname style
- fontname
in which
style is one of the four
case-insensitive strings:
"PLAIN"
,
"BOLD"
,
"BOLDITALIC"
, or
"ITALIC"
, and pointsize is a positive decimal integer
representation of the point size.
For example, if you want a font that is Arial, bold, with
a point size of 18, you would call this method with:
"Arial-BOLD-18".
This is equivalent to calling the Font constructor :
new Font("Arial", Font.BOLD, 18);
and the values are interpreted as specified by that constructor.
A valid trailing decimal field is always interpreted as the pointsize.
Therefore a fontname containing a trailing decimal value should not
be used in the fontname only form.
If a style name field is not one of the valid style strings, it is
interpreted as part of the font name, and the default style is used.
Only one of ' ' or '-' may be used to separate fields in the input.
The identified separator is the one closest to the end of the string
which separates a valid pointsize, or a valid style name from
the rest of the string.
Null (empty) pointsize and style fields are treated
as valid fields with the default value for that field.
Some font names may include the separator characters ' ' or '-'.
If str
is not formed with 3 components, e.g. such that
style
or pointsize
fields are not present in
str
, and fontname
also contains a
character determined to be the separator character
then these characters where they appear as intended to be part of
fontname
may instead be interpreted as separators
so the font name may not be properly recognised.
The default size is 12 and the default style is PLAIN.
If str
does not specify a valid size, the returned
Font
has a size of 12. If str
does not
specify a valid style, the returned Font has a style of PLAIN.
If you do not specify a valid font name in
the str
argument, this method will return
a font with the family name "Dialog".
To determine what font family names are available on
your system, use the
GraphicsEnvironment.getAvailableFontFamilyNames()
method.
If str
is null
, a new Font
is returned with the family name "Dialog", a size of 12 and a
PLAIN style.
Returns:
the Font
object that str
describes, or a new default Font
if
str
is null
.
Parameters:
- str - the name of the font, or null
Since:
JDK1.1
See Also:
Font.getFamily()
,