* #### Font
public Font(double size)
Constructs a font using the default face "System". The underlying font used is determined by the implementation based on the typical UI font for the current UI environment.
Parameters:
`size` \- the font size to use
* #### Font
public Font([String](../../../java/lang/String.html "class in java.lang") name,
double size)
Constructs a font using the specified full face name and size
Parameters:
`name` \- full name of the font.
`size` \- the font size to use
Method Detail
* #### getDefault
public static [Font](../../../javafx/scene/text/Font.html "class in javafx.scene.text") getDefault()
Gets the default font which will be from the family "System", and typically the style "Regular", and be of a size consistent with the user's desktop environment, to the extent that can be determined.
Returns:
The default font.
* #### getFamilies
public static [List](../../../java/util/List.html "interface in java.util")<[String](../../../java/lang/String.html "class in java.lang")> getFamilies()
Gets all the font families installed on the user's system, including any application fonts or SDK fonts. This call has performance considerations as looking up all of the fonts may be an expensive operation the first time.
Returns:
The list containing all available font families.
* #### getFontNames
public static [List](../../../java/util/List.html "interface in java.util")<[String](../../../java/lang/String.html "class in java.lang")> getFontNames()
Gets the names of all fonts that are installed on the users system, including any application fonts and SDK fonts. This call has performance considerations as looking up all of the fonts may be an expensive operation the first time.
Returns:
The list containing all available fonts.
* #### getFontNames
public static [List](../../../java/util/List.html "interface in java.util")<[String](../../../java/lang/String.html "class in java.lang")> getFontNames([String](../../../java/lang/String.html "class in java.lang") family)
Gets the names of all fonts in the specified font family that are installed on the users system, including any application fonts and SDK fonts. This call has performance considerations as looking up all of the fonts may be an expensive operation the first time.
Parameters:
`family` \- the font family
Returns:
The list containing the fonts for the given family.
* #### font
public static [Font](../../../javafx/scene/text/Font.html "class in javafx.scene.text") font([String](../../../java/lang/String.html "class in java.lang") family,
[FontWeight](../../../javafx/scene/text/FontWeight.html "enum in javafx.scene.text") weight,
[FontPosture](../../../javafx/scene/text/FontPosture.html "enum in javafx.scene.text") posture,
double size)
Searches for an appropriate font based on the font family name and weight and posture style. This method is not guaranteed to return a specific font, but does its best to find one that fits the specified requirements.
A null or empty value for family allows the implementation to select any suitable font.
Parameters:
`family` \- The family of the font
`weight` \- The weight of the font
`posture` \- The posture or posture of the font
`size` \- The point size of the font. This can be a fractional value, but must not be negative. If the size is < 0 the default size will be used.
Returns:
The font that best fits the specified requirements.
* #### font
public static [Font](../../../javafx/scene/text/Font.html "class in javafx.scene.text") font([String](../../../java/lang/String.html "class in java.lang") family,
[FontWeight](../../../javafx/scene/text/FontWeight.html "enum in javafx.scene.text") weight,
double size)
Searches for an appropriate font based on the font family name and weight style. This method is not guaranteed to return a specific font, but does its best to find one that fits the specified requirements. A null or empty value for family allows the implementation to select any suitable font.
Parameters:
`family` \- The family of the font
`weight` \- The weight of the font
`size` \- The point size of the font. This can be a fractional value, but must not be negative. If the size is < 0 the default size will be used.
Returns:
The font that best fits the specified requirements.
* #### font
public static [Font](../../../javafx/scene/text/Font.html "class in javafx.scene.text") font([String](../../../java/lang/String.html "class in java.lang") family,
[FontPosture](../../../javafx/scene/text/FontPosture.html "enum in javafx.scene.text") posture,
double size)
Searches for an appropriate font based on the font family name and posture style. This method is not guaranteed to return a specific font, but does its best to find one that fits the specified requirements. A null or empty value for family allows the implementation to select any suitable font.
Parameters:
`family` \- The family of the font
`posture` \- The posture or posture of the font
`size` \- The point size of the font. This can be a fractional value, but must not be negative. If the size is < 0 the default size will be used.
Returns:
The font that best fits the specified requirements.
* #### font
public static [Font](../../../javafx/scene/text/Font.html "class in javafx.scene.text") font([String](../../../java/lang/String.html "class in java.lang") family,
double size)
Searches for an appropriate font based on the font family name and size. This method is not guaranteed to return a specific font, but does its best to find one that fits the specified requirements. A null or empty value for family allows the implementation to select any suitable font.
Parameters:
`family` \- The family of the font
`size` \- The point size of the font. This can be a fractional value, but must not be negative. If the size is < 0 the default size will be used.
Returns:
The font that best fits the specified requirements.
* #### font
public static [Font](../../../javafx/scene/text/Font.html "class in javafx.scene.text") font([String](../../../java/lang/String.html "class in java.lang") family)
Searches for an appropriate font based on the given font family name and default font size. This method is not guaranteed to return a specific font, but does its best to find one that fits the specified requirements. A null or empty value for family allows the implementation to select any suitable font.
Parameters:
`family` \- The family of the font
Returns:
The font that best fits the specified requirements.
* #### font
public static [Font](../../../javafx/scene/text/Font.html "class in javafx.scene.text") font(double size)
Searches for an appropriate font based on the default font family name and given font size. This method is not guaranteed to return a specific font, but does its best to find one that fits the specified requirements.
Parameters:
`size` \- The point size of the font. This can be a fractional value, but must not be negative. If the size is < 0 the default size will be used.
Returns:
The font that best fits the specified requirements.
* #### getName
public final [String](../../../java/lang/String.html "class in java.lang") getName()
The full font name. This name includes both the family name and the style variant within that family. For example, for a plain Arial font this would be "Arial Regular" and for a bolded Arial font this would be "Arial Bold". The precise name to use when loading a font is defined within each font file as the full font name. For example, "Proxima Nova ExtraCondensed Bold Italic" would refer to a specific Proxima Nova font. A null or empty name allows the implementation to select any suitable font.
There is a single unified way to load all of application supplied (via `Font.loadFont()`, JavaFX runtime delivered fonts, and system installed fonts. Simply create the font by specifying the full name of the font you want to load. If the specific font cannot be located, then a fallback or default font will be used. The "name" will be updated to reflect the actual name of the font being used. A load failure condition can be discovered by checking the name of the Font with the name you tried to load.
Note that if you wish to locate a font by font family and style then you can use one of the [font(java.lang.String, javafx.scene.text.FontWeight, javafx.scene.text.FontPosture, double)](../../../javafx/scene/text/Font.html#font%28java.lang.String,javafx.scene.text.FontWeight,javafx.scene.text.FontPosture,double%29) factory methods defined in this class.
Default value:
empty string
Returns:
the full font name
* #### getFamily
public final [String](../../../java/lang/String.html "class in java.lang") getFamily()
Returns the family of this font.
Returns:
The family of this font.
* #### getStyle
public final [String](../../../java/lang/String.html "class in java.lang") getStyle()
The font specified string describing the style within the font family.
Returns:
The style name of this font.
* #### getSize
public final double getSize()
The point size for this font. This may be a fractional value such as`11.5`. If the specified value is < 0 the default size will be used.
Default value:
12
Returns:
the point size for this font
* #### loadFont
public static [Font](../../../javafx/scene/text/Font.html "class in javafx.scene.text") loadFont([String](../../../java/lang/String.html "class in java.lang") urlStr,
double size)
Loads a font resource from the specified URL. If the load is successful such that the location is readable, and it represents a supported font format then a `Font` object will be returned.
If a security manager is present, the application must have both permission to read from the specified URL location and the [FXPermission](../../../javafx/util/FXPermission.html "class in javafx.util") "loadFont". If the application does not have permission to read from the specified URL location, then null is returned. If the application does not have the "loadFont" permission then this method will return the default system font with the specified font size.
Any failure such as a malformed URL being unable to locate or read from the resource, or if it doesn't represent a font, will result in a `null` return. It is the application's responsibility to check this before use.
On a successful (non-null) return the font will be registered with the FX graphics system for creation by available constructors and factory methods, and the application should use it in this manner rather than calling this method again, which would repeat the overhead of downloading and installing the font.
The font `size` parameter is a convenience so that in typical usage the application can directly use the returned (non-null) font rather than needing to create one via a constructor. Invalid sizes are those <=0 and will result in a default size.
If the URL represents a local disk file, then no copying is performed and the font file is required to persist for the lifetime of the application. Updating the file in any manner will result in unspecified and likely undesired behaviours.
Parameters:
`urlStr` \- from which to load the font, specified as a String.
`size` \- of the returned font.
Returns:
the Font, or null if the font cannot be created.
* #### loadFonts
public static [Font](../../../javafx/scene/text/Font.html "class in javafx.scene.text")[] loadFonts([String](../../../java/lang/String.html "class in java.lang") urlStr,
double size)
Loads font resources from the specified URL. If the load is successful such that the location is readable, and it represents a supported font format then an array of `Font` will be returned.
The use case for this method is for loading all fonts from a TrueType Collection (TTC).
If a security manager is present, the application must have both permission to read from the specified URL location and the [FXPermission](../../../javafx/util/FXPermission.html "class in javafx.util") "loadFont". If the application does not have permission to read from the specified URL location, then null is returned. If the application does not have the "loadFont" permission then this method will return an array of one element which is the default system font with the specified font size.
Any failure such as a malformed URL being unable to locate or read from the resource, or if it doesn't represent a font, will result in a `null` return. It is the application's responsibility to check this before use.
On a successful (non-null) return the fonts will be registered with the FX graphics system for creation by available constructors and factory methods, and the application should use it in this manner rather than calling this method again, which would repeat the overhead of downloading and installing the fonts.
The font `size` parameter is a convenience so that in typical usage the application can directly use the returned (non-null) font rather than needing to create one via a constructor. Invalid sizes are those <=0 and will result in a default size.
If the URL represents a local disk file, then no copying is performed and the font file is required to persist for the lifetime of the application. Updating the file in any manner will result in unspecified and likely undesired behaviours.
Parameters:
`urlStr` \- from which to load the fonts, specified as a String.
`size` \- of the returned fonts.
Returns:
array of Font, or null if the fonts cannot be created.
Since:
9
* #### loadFont
public static [Font](../../../javafx/scene/text/Font.html "class in javafx.scene.text") loadFont([InputStream](../../../java/io/InputStream.html "class in java.io") in,
double size)
Loads a font resource from the specified input stream. If the load is successful such that the stream can be fully read, and it represents a supported font format then a`Font` object will be returned.
If a security manager is present, the application must have the [FXPermission](../../../javafx/util/FXPermission.html "class in javafx.util") "loadFont". If the application does not have permission then this method will return the default system font with the specified font size.
Any failure such as abbreviated input, or an unsupported font format will result in a `null` return. It is the application's responsibility to check this before use.
On a successful (non-null) return the font will be registered with the FX graphics system for creation by available constructors and factory methods, and the application should use it in this manner rather than calling this method again, which would repeat the overhead of re-reading and installing the font.
The font `size` parameter is a convenience so that in typical usage the application can directly use the returned (non-null) font rather than needing to create one via a constructor. Invalid sizes are those <=0 and will result in a default size.
This method does not close the input stream.
Parameters:
`in` \- stream from which to load the font.
`size` \- of the returned font.
Returns:
the Font, or null if the font cannot be created.
* #### loadFonts
public static [Font](../../../javafx/scene/text/Font.html "class in javafx.scene.text")[] loadFonts([InputStream](../../../java/io/InputStream.html "class in java.io") in,
double size)
Loads font resources from the specified input stream. If the load is successful such that the stream can be fully read, and it represents a supported font format then an array of `Font` will be returned.
The use case for this method is for loading all fonts from a TrueType Collection (TTC).
If a security manager is present, the application must have the [FXPermission](../../../javafx/util/FXPermission.html "class in javafx.util") "loadFont". If the application does not have permission then this method will return the default system font with the specified font size.
Any failure such as abbreviated input, or an unsupported font format will result in a `null` return. It is the application's responsibility to check this before use.
On a successful (non-null) return the fonts will be registered with the FX graphics system for creation by available constructors and factory methods, and the application should use it in this manner rather than calling this method again, which would repeat the overhead of re-reading and installing the fonts.
The font `size` parameter is a convenience so that in typical usage the application can directly use the returned (non-null) fonts rather than needing to re-create via a constructor. Invalid sizes are those <=0 and will result in a default size.
This method does not close the input stream.
Parameters:
`in` \- stream from which to load the fonts.
`size` \- of the returned fonts.
Returns:
array of Font, or null if the fonts cannot be created.
Since:
9
* #### toString
public [String](../../../java/lang/String.html "class in java.lang") toString()
Converts this `Font` object to a `String` representation. The String representation is for informational use only and will change. Do not use this string representation for any programmatic purpose.
Overrides:
`[toString](../../../java/lang/Object.html#toString%28%29)` in class `[Object](../../../java/lang/Object.html "class in java.lang")`
Returns:
a string representation of the object.
* #### equals
public boolean equals([Object](../../../java/lang/Object.html "class in java.lang") obj)
Indicates whether some other object is "equal to" this one.
Overrides:
`[equals](../../../java/lang/Object.html#equals%28java.lang.Object%29)` in class `[Object](../../../java/lang/Object.html "class in java.lang")`
Parameters:
`obj` \- the reference object with which to compare.
Returns:
`true` if this object is equal to the `obj` argument; `false` otherwise.
See Also:
[Object.hashCode()](../../../java/lang/Object.html#hashCode%28%29), [HashMap](../../../java/util/HashMap.html "class in java.util")
* #### hashCode
public int hashCode()
Returns a hash code for this `Font` object.
Overrides:
`[hashCode](../../../java/lang/Object.html#hashCode%28%29)` in class `[Object](../../../java/lang/Object.html "class in java.lang")`
Returns:
a hash code for this `Font` object.
See Also:
[Object.equals(java.lang.Object)](../../../java/lang/Object.html#equals%28java.lang.Object%29), [System.identityHashCode(java.lang.Object)](../../../java/lang/System.html#identityHashCode%28java.lang.Object%29)