APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.awt

public abstract Class Toolkit

extends Object
Class Inheritance
Known Direct Subclasses
sun.awt.HeadlessToolkit, sun.awt.SunToolkit
Imports
java.awt.datatransfer.Clipboard, java.awt.dnd.DragGestureListener, .DragGestureRecognizer, .DragSource, java.awt.event.AWTEventListener, .AWTEventListenerProxy, .ActionEvent, .AdjustmentEvent, .ComponentEvent, .ContainerEvent, .FocusEvent, .HierarchyEvent, .InputEvent, .InputMethodEvent, .InvocationEvent, .ItemEvent, .KeyEvent, .MouseEvent, .PaintEvent, .TextEvent, .WindowEvent, java.awt.im.InputMethodHighlight, java.awt.image.ColorModel, .ImageObserver, .ImageProducer, java.beans.PropertyChangeEvent, .PropertyChangeListener, .PropertyChangeSupport, java.io.File, .FileInputStream, java.net.URL, java.util.ArrayList, .Arrays, .EventListener, .HashMap, .Map, .MissingResourceException, .Properties, .ResourceBundle, .ServiceLoader, .Set, .WeakHashMap, java.util.stream.Collectors, javax.accessibility.AccessibilityProvider, sun.awt.AWTAccessor, .HeadlessToolkit, .PeerEvent, .PlatformGraphicsInfo, .SunToolkit

This class is the abstract superclass of all actual implementations of the Abstract Window Toolkit. Subclasses of the Toolkit class are used to bind the various components to particular native toolkit implementations.

Many GUI events may be delivered to user asynchronously, if the opposite is not specified explicitly. As well as many GUI operations may be performed asynchronously. This fact means that if the state of a component is set, and then the state immediately queried, the returned value may not yet reflect the requested change. This behavior includes, but is not limited to:

Most applications should not call any of the methods in this class directly. The methods defined by Toolkit are the "glue" that joins the platform-independent classes in the java.awt package with their counterparts in java.awt.peer. Some methods defined by Toolkit query the native operating system directly.

Authors
Sami Shaio, Arthur van Hoff, Fred Ecks
Since
1.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
Toolkit.DesktopPropertyChangeSupport

This is a utility class to support desktop properties.

private static class
private static class

Field Summary

Modifier and TypeField and Description
private static String
atNames

Used internally by the assistive technologies functions; set at init time and used at load time

private int[]
protected final Map<String, Object>
desktopProperties

The desktop properties.

protected final PropertyChangeSupport
desktopPropsSupport

The desktop properties change support.

private static volatile long
private AWTEventListener
private final WeakHashMap<AWTEventListener, Toolkit.SelectiveAWTEventListener>
private static boolean
loaded

Warning

This is a temporary workaround for a problem in the way the AWT loads native libraries.

private static final int
private static ResourceBundle
private static ResourceBundle
resources

Support for I18N: any visible strings should be stored in sun.awt.resources.awt.properties.

private static Toolkit
toolkit

The default toolkit.

Constructor Summary

AccessConstructor and Description
protected
Toolkit()

Constructs a Toolkit.

Method Summary

Modifier and TypeMethod and Description
public void
addAWTEventListener(AWTEventListener
the event listener.
listener
,
long
the bitmask of event types to receive
eventMask
)

Adds an AWTEventListener to receive all AWTEvents dispatched system-wide that conform to the given eventMask.

public void
addPropertyChangeListener(String
The name of the property to listen for
name
,
PropertyChangeListener
The property change listener
pcl
)

Adds the specified property change listener for the named desktop property.

public boolean

Returns:

true if events from extra mouse buttons are allowed to be processed and posted; false otherwise
areExtraMouseButtonsEnabled
()

Reports whether events from extra mouse buttons are allowed to be processed and posted into EventQueue.

public abstract void
beep()

Emits an audio beep depending on native system settings and hardware capabilities.

public abstract int

Returns:

the bitwise inclusive OR of the ImageObserver flags for the image data that is currently available.
checkImage
(Image
the image whose status is being checked.
image
,
int
the width of the scaled version whose status is being checked, or -1.
width
,
int
the height of the scaled version whose status is being checked, or -1.
height
,
ImageObserver
the ImageObserver object to be notified as the image is being prepared.
observer
)

Indicates the construction status of a specified image that is being prepared for display.

pack-priv synchronized int
countAWTEventListeners(long eventMask)

public Cursor

Returns:

the cursor created
createCustomCursor
(Image
the image to display when the cursor is activated
cursor
,
Point
the X and Y of the large cursor's hot spot; the hotSpot values must be less than the Dimension returned by getBestCursorSize
hotSpot
,
String
a localized description of the cursor, for Java Accessibility use
name
)

Creates a new custom cursor object.

public <
the type of DragGestureRecognizer to create
T extends DragGestureRecognizer
>
T

Returns:

the new object or null. Always returns null if GraphicsEnvironment.isHeadless() returns true.
createDragGestureRecognizer
(Class<T>
The abstract class of the required recognizer
abstractRecognizerClass
,
DragSource
The DragSource
ds
,
Component
The Component target for the DragGestureRecognizer
c
,
int
The actions permitted for the gesture
srcActions
,
DragGestureListener
The DragGestureListener
dgl
)

Creates a concrete, platform dependent, subclass of the abstract DragGestureRecognizer class requested, and associates it with the DragSource, Component and DragGestureListener specified.

public abstract Image

Returns:

an image which gets its pixel data from the specified file.
createImage
(String
the name of a file containing pixel data in a recognized file format.
filename
)

Returns an image which gets pixel data from the specified file.

public abstract Image

Returns:

an image which gets its pixel data from the specified URL.
createImage
(URL
the URL to use in fetching the pixel data.
url
)

Returns an image which gets pixel data from the specified URL.

public abstract Image

Returns:

an image with the specified image producer.
createImage
(ImageProducer
the image producer to be used.
producer
)

Creates an image with the specified image producer.

public Image

Returns:

an image.
createImage
(byte[]
an array of bytes, representing image data in a supported image format.
imagedata
)

Creates an image which decodes the image stored in the specified byte array.

public abstract Image

Returns:

an image.
createImage
(byte[]
an array of bytes, representing image data in a supported image format.
imagedata
,
int
the offset of the beginning of the data in the array.
imageoffset
,
int
the length of the data in the array.
imagelength
)

Creates an image which decodes the image stored in the specified byte array, and at the specified offset and length.

private static PropertyChangeSupport
private static AWTEventListener
pack-priv static boolean
enabledOnToolkit(long eventMask)

private static void
fallbackToLoadClassForAT(String
the name of the class to be loaded
atName
)

When a service provider for Assistive Technology is not found look for a supporting class on the class path and instantiate it.

public AWTEventListener[]

Returns:

all of the AWTEventListeners or an empty array if no listeners are currently registered
getAWTEventListeners
()

Returns an array of all the AWTEventListeners registered on this toolkit.

public AWTEventListener[]

Returns:

all of the AWTEventListeners registered on this toolkit for the specified event types, or an empty array if no such listeners are currently registered
getAWTEventListeners
(long
the bitmask of event types to listen for
eventMask
)

Returns an array of all the AWTEventListeners registered on this toolkit which listen to all of the event types specified in the eventMask argument.

public Dimension

Returns:

the closest matching supported cursor size, or a dimension of 0,0 if the Toolkit implementation doesn't support custom cursors.
getBestCursorSize
(int
the preferred cursor width the component would like to use.
preferredWidth
,
int
the preferred cursor height the component would like to use.
preferredHeight
)

Returns the supported cursor dimension which is closest to the desired sizes.

public abstract ColorModel

Returns:

the color model of this toolkit's screen.
getColorModel
()

Determines the color model of this toolkit's screen.

public static synchronized Toolkit

Returns:

the default toolkit.
getDefaultToolkit
()

Gets the default toolkit.

public final synchronized Object

Returns:

the value for the specified desktop property
getDesktopProperty
(String
the property name
propertyName
)

Obtains a value for the specified desktop property.

pack-priv static EventQueue
public abstract String[]

Returns:

the names of the available fonts in this toolkit.
getFontList
()

Returns the names of the available fonts in this toolkit.

public abstract FontMetrics

Returns:

the screen metrics of the specified font in this toolkit
getFontMetrics
(Font
a font
font
)
Deprecated As of JDK version 1.2, replaced by the Font method getLineMetrics.

Gets the screen device metrics for rendering of the font.

public abstract Image

Returns:

an image which gets its pixel data from the specified file.
getImage
(String
the name of a file containing pixel data in a recognized file format.
filename
)

Returns an image which gets pixel data from the specified file, whose format can be either GIF, JPEG or PNG.

public abstract Image

Returns:

an image which gets its pixel data from the specified URL.
getImage
(URL
the URL to use in fetching the pixel data.
url
)

Returns an image which gets pixel data from the specified URL.

public boolean

Returns:

true if the given key is currently in its "on" state; otherwise false
getLockingKeyState
(int
the key code
keyCode
)

Returns whether the given locking key on the keyboard is currently in its "on" state.

public int

Returns:

the maximum number of colors, or zero if custom cursors are not supported by this Toolkit implementation.
getMaximumCursorColors
()

Returns the maximum number of colors the Toolkit supports in a custom cursor palette.

public int

Returns:

the modifier mask on the Event class that is used for menu shortcuts on this toolkit.
getMenuShortcutKeyMask
()
Deprecated since 10. It is recommended that extended modifier keys and getMenuShortcutKeyMaskEx() be used instead

Determines which modifier key is the appropriate accelerator key for menu shortcuts.

public int

Returns:

the modifier mask on the InputEvent class that is used for menu shortcuts on this toolkit
getMenuShortcutKeyMaskEx
()

Determines which extended modifier key is the appropriate accelerator key for menu shortcuts.

protected static Container

Returns:

the native container object for the component
getNativeContainer
(Component
the component to fetch the container for
c
)

Give native peers the ability to query the native container given a native component (eg the direct parent may be lightweight).

public abstract PrintJob

Returns:

a PrintJob object, or null if the user cancelled the print job.
getPrintJob
(Frame
the parent of the print dialog. May not be null.
frame
,
String
the title of the PrintJob. A null title is equivalent to "".
jobtitle
,
Properties
a Properties object containing zero or more properties. Properties are not standardized and are not consistent across implementations. Because of this, PrintJobs which require job and page control should use the version of this function which takes JobAttributes and PageAttributes objects. This object may be updated to reflect the user's job choices on exit. May be null.
props
)

Gets a PrintJob object which is the result of initiating a print operation on the toolkit's platform.

public PrintJob

Returns:

a PrintJob object, or null if the user cancelled the print job.
getPrintJob
(Frame
the parent of the print dialog. May not be null.
frame
,
String
the title of the PrintJob. A null title is equivalent to "".
jobtitle
,
JobAttributes
a set of job attributes which will control the PrintJob. The attributes will be updated to reflect the user's choices as outlined in the JobAttributes documentation. May be null.
jobAttributes
,
PageAttributes
a set of page attributes which will control the PrintJob. The attributes will be applied to every page in the job. The attributes will be updated to reflect the user's choices as outlined in the PageAttributes documentation. May be null.
pageAttributes
)

Gets a PrintJob object which is the result of initiating a print operation on the toolkit's platform.

public static String

Returns:

the value of the property or the default value if the property was not found
getProperty
(String
the key
key
,
String
the default value
defaultValue
)

Gets a property with the specified key and default.

public PropertyChangeListener[]

Returns:

all of this toolkit's PropertyChangeListener objects wrapped in java.beans.PropertyChangeListenerProxy objects or an empty array if no listeners are added
getPropertyChangeListeners
()

Returns an array of all the property change listeners registered on this toolkit.

public PropertyChangeListener[]

Returns:

all of the PropertyChangeListener objects associated with the specified name of a desktop property or an empty array if no such listeners are added
getPropertyChangeListeners
(String
the named property
propertyName
)

Returns an array of all property change listeners associated with the specified name of a desktop property.

public Insets

Returns:

the insets of this toolkit's screen, in pixels.
getScreenInsets
(GraphicsConfiguration
a GraphicsConfiguration
gc
)

Gets the insets of the screen.

public abstract int

Returns:

this toolkit's screen resolution, in dots-per-inch.
getScreenResolution
()

Returns the screen resolution in dots-per-inch.

public abstract Dimension

Returns:

the size of this toolkit's screen, in pixels.
getScreenSize
()

Gets the size of the screen.

public abstract Clipboard

Returns:

the system Clipboard
getSystemClipboard
()

Gets the singleton instance of the system Clipboard which interfaces with clipboard facilities provided by the native platform.

public final EventQueue

Returns:

the EventQueue for this application
getSystemEventQueue
()

Returns the EventQueue for this application.

protected abstract EventQueue

Returns:

the EventQueue object
getSystemEventQueueImpl
()

A method used by toolkit subclasses to get the EventQueue.

public Clipboard

Returns:

the system selection as a Clipboard, or null if the native platform does not support a system selection Clipboard
getSystemSelection
()

Gets the singleton instance of the system selection as a Clipboard object.

private static void
initAssistiveTechnologies()

Initializes properties related to assistive technologies.

protected void
initializeDesktopProperties()

initializeDesktopProperties

private static native void
initIDs()

Initialize JNI field and method ids

private static void
public boolean

Returns:

true, if current toolkit supports the always-on-top mode, otherwise returns false
isAlwaysOnTopSupported
()

Returns whether the always-on-top mode is supported by this toolkit.

public boolean

Returns:

true if dynamic layout of Containers on resize is currently active, false otherwise.
isDynamicLayoutActive
()

Returns whether dynamic layout of Containers on resize is currently enabled on the underlying operating system and/or window manager.

protected boolean

Returns:

true if validation of Containers is done dynamically, false if validation is done after resizing is finished.
isDynamicLayoutSet
()

Returns whether the layout of Containers is validated dynamically during resizing, or statically, after resizing is complete.

public boolean

Returns:

true is this frame state is supported by this Toolkit implementation, false otherwise.
isFrameStateSupported
(int
one of named frame state constants.
state
)

Returns whether Toolkit supports this state for Frames.

public abstract boolean

Returns:

true, if current toolkit supports given modal exclusion type, false otherwise
isModalExclusionTypeSupported
(Dialog.ModalExclusionType
modal exclusion type to be checked for support by this toolkit
modalExclusionType
)

Returns whether the given modal exclusion type is supported by this toolkit.

public abstract boolean

Returns:

true, if current toolkit supports given modality type, false otherwise
isModalityTypeSupported
(Dialog.ModalityType
modality type to be checked for support by this toolkit
modalityType
)

Returns whether the given modality type is supported by this toolkit.

protected Object

Returns:

the desktop property or null
lazilyLoadDesktopProperty
(String
the name
name
)

An opportunity to lazily evaluate desktop property values.

private static void
loadAssistiveTechnologies()

Loads accessibility support using the property assistive_technologies.

pack-priv static void
protected void
loadSystemColors(int[]
an integer array.
systemColors
)

Fills in the integer array that is supplied as an argument with the current system color values.

public abstract Map<TextAttribute, ?>

Returns:

style attribute map, or null
mapInputMethodHighlight
(InputMethodHighlight
input method highlight
highlight
)

Returns a map of visual attributes for the abstract level description of the given input method highlight, or null if no mapping is found.

private static void
newAWTError(Throwable
the original exception
e
,
String
the error message
s
)

Rethrow the AWTError but include the cause.

pack-priv void
public abstract boolean

Returns:

true if the image has already been fully prepared; false otherwise.
prepareImage
(Image
the image for which to prepare a screen representation.
image
,
int
the width of the desired screen representation, or -1.
width
,
int
the height of the desired screen representation, or -1.
height
,
ImageObserver
the ImageObserver object to be notified as the image is being prepared.
observer
)

Prepares an image for rendering.

public void
removeAWTEventListener(AWTEventListener
the event listener.
listener
)

Removes an AWTEventListener from receiving dispatched AWTEvents.

public void
removePropertyChangeListener(String
The name of the property to remove
name
,
PropertyChangeListener
The property change listener
pcl
)

Removes the specified property change listener for the named desktop property.

protected final void
setDesktopProperty(String
the property name
name
,
Object
the new property value
newValue
)

Sets the named desktop property to the specified value and fires a property change event to notify any listeners that the value has changed.

public void
setDynamicLayout(final boolean
If true, Containers should re-layout their components as the Container is being resized. If false, the layout will be validated after resizing is completed.
dynamic
)

Controls whether the layout of Containers is validated dynamically during resizing, or statically, after resizing is complete.

public void
setLockingKeyState(int
the key code
keyCode
,
boolean
the state of the key
on
)

Sets the state of the given locking key on the keyboard.

private static void
public abstract void
sync()

Synchronizes this toolkit's graphics state.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait