Top Description Fields Constructors Methods
org.eclipse.swt.graphics

public final Class Font

extends Resource
Class Inheritance
Imports
org.eclipse.swt.*, org.eclipse.swt.internal.*, org.eclipse.swt.internal.gtk.*

Instances of this class manage operating system resources that define how text looks when it is displayed. Fonts may be constructed by providing a device and either name, size and style information or a FontData object which encapsulates this data.

Application code must explicitly invoke the Font.dispose() method to release the operating system resources managed by each instance when those instances are no longer required.

See Also
FontData, Font snippets, SWT Examples: GraphicsExample, PaintExample, Sample code and further information

Field Summary

Modifier and TypeField and Description
public long
handle

the handle to the OS font resource (Warning: This field is platform dependent)

Important Note

This field is not part of the SWT public API.

Inherited from org.eclipse.swt.graphics.Resource:
device

Constructor Summary

AccessConstructor and Description
pack-priv
Font(Device device)

public
Font(Device
the device to create the font on
device
,
FontData
the FontData that describes the desired font (must not be null)
fd
)

Constructs a new font given a device and font data which describes the desired font's appearance.

public
Font(Device
the device to create the font on
device
,
FontData[]
the array of FontData that describes the desired font (must not be null)
fds
)

Constructs a new font given a device and an array of font data which describes the desired font's appearance.

public
Font(Device
the device to create the font on
device
,
String
the name of the font (must not be null)
name
,
int
the font height in points
height
,
int
a bit or combination of NORMAL, BOLD, ITALIC
style
)

Constructs a new font given a device, a font name, the height of the desired font in points, and a font style.

pack-priv
Font(Device device, String name, float height, int style)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
public boolean

Returns:

true if the object is the same as this object and false otherwise
equals
(Object
the object to compare with this object
object
)

Overrides java.lang.Object.equals.

Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.
public FontData[]

Returns:

an array of font data objects describing the receiver
getFontData
()

Returns an array of FontDatas representing the receiver.

public static Font
gtk_new(Device
the device on which to allocate the color
device
,
long
the handle for the font
handle
)

Invokes platform specific functionality to allocate a new font.

public int

Returns:

the receiver's hash
hashCode
()

Overrides java.lang.Object.hashCode.

Returns an integer hash code for the receiver.
pack-priv void
init(String name, float height, int style, byte[] fontString)

public boolean

Returns:

true when the font is disposed and false otherwise
isDisposed
()

Implements abstract org.eclipse.swt.graphics.Resource.isDisposed.

Returns true if the font has been disposed, and false otherwise.
public String

Returns:

a string representation of the receiver
toString
()

Overrides java.lang.Object.toString.

Returns a string containing a concise, human-readable description of the receiver.
Inherited from org.eclipse.swt.graphics.Resource:
disposegetDeviceignoreNonDisposedinitinitNonDisposeTrackingsetNonDisposeHandler

Field Detail

handleback to summary
public long handle

the handle to the OS font resource (Warning: This field is platform dependent)

Important Note

This field is not part of the SWT public API. It is marked public only so that it can be shared within the packages provided by SWT. It is not available on all platforms and should never be accessed from application code.

Constructor Detail

Fontback to summary
pack-priv Font(Device device)
Fontback to summary
public Font(Device device, FontData fd)

Constructs a new font given a device and font data which describes the desired font's appearance.

You must dispose the font when it is no longer required.

Parameters
device:Device

the device to create the font on

fd:FontData

the FontData that describes the desired font (must not be null)

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if device is null and there is no current device
  • ERROR_NULL_ARGUMENT - if the fd argument is null
SWTError:
  • ERROR_NO_HANDLES - if a font could not be created from the given font data
See Also
dispose()
Fontback to summary
public Font(Device device, FontData[] fds)

Constructs a new font given a device and an array of font data which describes the desired font's appearance.

You must dispose the font when it is no longer required.

Parameters
device:Device

the device to create the font on

fds:FontData[]

the array of FontData that describes the desired font (must not be null)

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if device is null and there is no current device
  • ERROR_NULL_ARGUMENT - if the fds argument is null
  • ERROR_INVALID_ARGUMENT - if the length of fds is zero
  • ERROR_NULL_ARGUMENT - if any fd in the array is null
SWTError:
  • ERROR_NO_HANDLES - if a font could not be created from the given font data
Since
2.1
See Also
dispose()
Fontback to summary
public Font(Device device, String name, int height, int style)

Constructs a new font given a device, a font name, the height of the desired font in points, and a font style.

You must dispose the font when it is no longer required.

Parameters
device:Device

the device to create the font on

name:String

the name of the font (must not be null)

height:int

the font height in points

style:int

a bit or combination of NORMAL, BOLD, ITALIC

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if device is null and there is no current device
  • ERROR_NULL_ARGUMENT - if the name argument is null
  • ERROR_INVALID_ARGUMENT - if the height is negative
SWTError:
  • ERROR_NO_HANDLES - if a font could not be created from the given arguments
See Also
dispose()
Fontback to summary
pack-priv Font(Device device, String name, float height, int style)

Method Detail

destroyback to summary
pack-priv void destroy()

Overrides org.eclipse.swt.graphics.Resource.destroy.

Annotations
@Override
equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.

Parameters
object:Object

the object to compare with this object

Returns:boolean

true if the object is the same as this object and false otherwise

Annotations
@Override
See Also
hashCode
getFontDataback to summary
public FontData[] getFontData()

Returns an array of FontDatas representing the receiver. On Windows, only one FontData will be returned per font. On X however, a Font object may be composed of multiple X fonts. To support this case, we return an array of font data objects.

Returns:FontData[]

an array of font data objects describing the receiver

Exceptions
SWTException:
  • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
gtk_newback to summary
public static Font gtk_new(Device device, long handle)

Invokes platform specific functionality to allocate a new font.

Important Note

This method is not part of the public API for Font. It is marked public only so that it can be shared within the packages provided by SWT. It is not available on all platforms, and should never be called from application code.

Parameters
device:Device

the device on which to allocate the color

handle:long

the handle for the font

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns an integer hash code for the receiver. Any two objects that return true when passed to equals must return the same value for this method.

Returns:int

the receiver's hash

Annotations
@Override
See Also
equals
initback to summary
pack-priv void init(String name, float height, int style, byte[] fontString)
isDisposedback to summary
public boolean isDisposed()

Implements abstract org.eclipse.swt.graphics.Resource.isDisposed.

Returns true if the font has been disposed, and false otherwise.

This method gets the dispose state for the font. When a font has been disposed, it is an error to invoke any other method (except dispose()) using the font.

Returns:boolean

true when the font is disposed and false otherwise

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string containing a concise, human-readable description of the receiver.

Returns:String

a string representation of the receiver

Annotations
@Override