| public abstract class java.awt Toolkit
|
Java SE 6 |
Toolkit are used to bind the various components
to particular native toolkit implementations.
Many GUI operations may be performed asynchronously. This means that if you set the state of a component, and then immediately query the state, the returned value may not yet reflect the requested change. This includes, but is not limited to:
ScrollPane.setScrollPosition
and then getScrollPosition may return an incorrect
value if the original request has not yet been processed.
setVisible(true) on a Window,
Frame or Dialog may occur
asynchronously.
setSize, setBounds or
setLocation on a Window,
Frame or Dialog are forwarded
to the underlying window management system and may be
ignored or modified. See java.awt.Window for
more information.
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.
| version | 1.203, 12/19/03 |
| since | JDK1.0 |
| Fields | |
|---|---|
| final protected Map | desktopProperties |
| final protected PropertyChangeSupport | desktopPropsSupport |
| Constructors | |
|---|---|
| public | Toolkit() |
| Methods | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| public void | addAWTEventListener(AWTEventListener listener, long eventMask) Details
Adds an AWTEventListener to receive all AWTEvents dispatched
system-wide that conform to the given eventMask.
First, if there is a security manager, its
Note: event listener use is not recommended for normal application use, but are intended solely to support special purpose facilities including support for accessibility, event record/playback, and diagnostic tracing. If listener is null, no exception is thrown and no action is performed.
| ||||||||||||||
| public void | addPropertyChangeListener(String name, PropertyChangeListener pcl) Details
Adds the specified property change listener for the named desktop
property.
If pcl is null, no exception is thrown and no action is performed.
| ||||||||||||||
| abstract public void | beep() Details
Emits an audio beep.
| ||||||||||||||
| abstract public int | checkImage(Image image, int width, int height, ImageObserver observer) Details
Indicates the construction status of a specified image that is
being prepared for display.
If the values of the width and height arguments are both
This method does not cause the image to begin loading.
An application must call
This method is called by the component's
Information on the flags returned by this method can be found
with the definition of the
| ||||||||||||||
| abstract protected ButtonPeer | createButton(Button target) throws HeadlessException Details
Creates this toolkit's implementation of Button using
the specified peer interface.
| ||||||||||||||
| abstract protected CanvasPeer | createCanvas(Canvas target) Details
Creates this toolkit's implementation of Canvas using
the specified peer interface.
| ||||||||||||||
| abstract protected CheckboxPeer | createCheckbox(Checkbox target) throws HeadlessException Details
Creates this toolkit's implementation of Checkbox using
the specified peer interface.
| ||||||||||||||
| abstract protected CheckboxMenuItemPeer | createCheckboxMenuItem(CheckboxMenuItem target) throws HeadlessException Details
Creates this toolkit's implementation of CheckboxMenuItem using
the specified peer interface.
| ||||||||||||||
| abstract protected ChoicePeer | createChoice(Choice target) throws HeadlessException Details
Creates this toolkit's implementation of Choice using
the specified peer interface.
| ||||||||||||||
| protected LightweightPeer | createComponent(Component target) Details
Creates a peer for a component or container. This peer is windowless
and allows the Component and Container classes to be extended directly
to create windowless components that are defined entirely in java.
| ||||||||||||||
| public Cursor | createCustomCursor(Image cursor, Point hotSpot, String name) throws IndexOutOfBoundsException, HeadlessException Details
Creates a new custom cursor object.
If the image to display is invalid, the cursor will be hidden (made
completely transparent), and the hotspot will be set to (0, 0).
Note that multi-frame images are invalid and may cause this method to hang.
| ||||||||||||||
| abstract protected DesktopPeer | createDesktopPeer(Desktop target) throws HeadlessException Details
Creates this toolkit's implementation of the Desktop
using the specified peer interface.
| ||||||||||||||
| abstract protected DialogPeer | createDialog(Dialog target) throws HeadlessException Details
Creates this toolkit's implementation of Dialog using
the specified peer interface.
| ||||||||||||||
| public DragGestureRecognizer<T> | createDragGestureRecognizer(Class abstractRecognizerClass, DragSource ds, Component c, int srcActions, DragGestureListener dgl) Details
Creates a concrete, platform dependent, subclass of the abstract
DragGestureRecognizer class requested, and associates it with the
DragSource, Component and DragGestureListener specified.
subclasses should override this to provide their own implementation
| ||||||||||||||
| abstract public DragSourceContextPeer | createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException Details
Creates the peer for a DragSourceContext.
Always throws InvalidDndOperationException if
GraphicsEnvironment.isHeadless() returns true.
| ||||||||||||||
| abstract protected FileDialogPeer | createFileDialog(FileDialog target) throws HeadlessException Details
Creates this toolkit's implementation of FileDialog using
the specified peer interface.
| ||||||||||||||
| abstract protected FramePeer | createFrame(Frame target) throws HeadlessException Details
Creates this toolkit's implementation of Frame using
the specified peer interface.
| ||||||||||||||
| abstract public Image | createImage(String filename) Details
Returns an image which gets pixel data from the specified file.
The returned Image is a new object which will not be shared
with any other caller of this method or its getImage variant.
This method first checks if there is a security manager installed.
If so, the method calls the security manager's
| ||||||||||||||
| abstract public Image | createImage(URL url) Details
Returns an image which gets pixel data from the specified URL.
The returned Image is a new object which will not be shared
with any other caller of this method or its getImage variant.
This method first checks if there is a security manager installed.
If so, the method calls the security manager's
| ||||||||||||||
| abstract public Image | createImage(ImageProducer producer) Details
Creates an image with the specified image producer.
| ||||||||||||||
| public Image | createImage(byte[] imagedata) Details
Creates an image which decodes the image stored in the specified
byte array.
The data must be in some image format, such as GIF or JPEG, that is supported by this toolkit.
| ||||||||||||||
| abstract public Image | createImage(byte[] imagedata, int imageoffset, int imagelength) Details
Creates an image which decodes the image stored in the specified
byte array, and at the specified offset and length.
The data must be in some image format, such as GIF or JPEG,
that is supported by this toolkit.
| ||||||||||||||
| abstract protected LabelPeer | createLabel(Label target) throws HeadlessException Details
Creates this toolkit's implementation of Label using
the specified peer interface.
| ||||||||||||||
| abstract protected ListPeer | createList(List target) throws HeadlessException Details
Creates this toolkit's implementation of List using
the specified peer interface.
| ||||||||||||||
| abstract protected MenuPeer | createMenu(Menu target) throws HeadlessException Details
Creates this toolkit's implementation of Menu using
the specified peer interface.
| ||||||||||||||
| abstract protected MenuBarPeer | createMenuBar(MenuBar target) throws HeadlessException Details
Creates this toolkit's implementation of MenuBar using
the specified peer interface.
| ||||||||||||||
| abstract protected MenuItemPeer | createMenuItem(MenuItem target) throws HeadlessException Details
Creates this toolkit's implementation of MenuItem using
the specified peer interface.
| ||||||||||||||
| abstract protected PanelPeer | createPanel(Panel target) Details
Creates this toolkit's implementation of Panel using
the specified peer interface.
| ||||||||||||||
| abstract protected PopupMenuPeer | createPopupMenu(PopupMenu target) throws HeadlessException Details
Creates this toolkit's implementation of PopupMenu using
the specified peer interface.
| ||||||||||||||
| abstract protected ScrollbarPeer | createScrollbar(Scrollbar target) throws HeadlessException Details
Creates this toolkit's implementation of Scrollbar using
the specified peer interface.
| ||||||||||||||
| abstract protected ScrollPanePeer | createScrollPane(ScrollPane target) throws HeadlessException Details
Creates this toolkit's implementation of ScrollPane using
the specified peer interface.
| ||||||||||||||
| abstract protected TextAreaPeer | createTextArea(TextArea target) throws HeadlessException Details
Creates this toolkit's implementation of TextArea using
the specified peer interface.
| ||||||||||||||
| abstract protected TextFieldPeer | createTextField(TextField target) throws HeadlessException Details
Creates this toolkit's implementation of TextField using
the specified peer interface.
| ||||||||||||||
| abstract protected WindowPeer | createWindow(Window target) throws HeadlessException Details
Creates this toolkit's implementation of Window using
the specified peer interface.
| ||||||||||||||
| protected void | initializeDesktopProperties() initializeDesktopProperties | ||||||||||||||
| protected Object | lazilyLoadDesktopProperty(String name) an opportunity to lazily evaluate desktop property values. | ||||||||||||||
| protected void | loadSystemColors(int[] systemColors) throws HeadlessException Details
Fills in the integer array that is supplied as an argument
with the current system color values.
| ||||||||||||||
| abstract public Map | mapInputMethodHighlight(InputMethodHighlight highlight) throws HeadlessException Details
Returns a map of visual attributes for the abstract level description
of the given input method highlight, or null if no mapping is found.
The style field of the input method highlight is ignored. The map
returned is unmodifiable.
| ||||||||||||||
| abstract public boolean | prepareImage(Image image, int width, int height, ImageObserver observer) Details
Prepares an image for rendering.
If the values of the width and height arguments are both
The image data is downloaded asynchronously in another thread, and an appropriately scaled screen representation of the image is generated.
This method is called by components
Information on the flags returned by this method can be found
with the definition of the
| ||||||||||||||
| public void | removeAWTEventListener(AWTEventListener listener) Details
Removes an AWTEventListener from receiving dispatched AWTEvents.
First, if there is a security manager, its Note: event listener use is not recommended for normal application use, but are intended solely to support special purpose facilities including support for accessibility, event record/playback, and diagnostic tracing. If listener is null, no exception is thrown and no action is performed.
| ||||||||||||||
| public void | removePropertyChangeListener(String name, PropertyChangeListener pcl) Details
Removes the specified property change listener for the named
desktop property.
If pcl is null, no exception is thrown and no action is performed.
| ||||||||||||||
| abstract public void | sync() Synchronizes this toolkit's graphics state. Some window systems may do buffering of graphics events. This method ensures that the display is up-to-date. It is useful for animation. | ||||||||||||||
| Properties | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| public boolean | isAlwaysOnTopSupported() Details
Returns whether the always-on-top mode is supported by this toolkit.
To detect whether the always-on-top mode is supported for a
particular Window, use Window#isAlwaysOnTopSupported.
| ||||||||||||||||||||
| public AWTEventListener[] | getAWTEventListeners() Details
Returns an array of all the AWTEventListeners
registered on this toolkit.
If there is a security manager, its checkPermission
method is called with an
AWTPermission("listenToAllAWTEvents") permission.
This may result in a SecurityException.
Listeners can be returned
within AWTEventListenerProxy objects, which also contain
the event mask for the given listener.
Note that listener objects
added multiple times appear only once in the returned array.
| ||||||||||||||||||||
| public AWTEventListener[] | getAWTEventListeners(long eventMask) Details
Returns an array of all the AWTEventListeners
registered on this toolkit which listen to all of the event
types specified in the eventMask argument.
If there is a security manager, its checkPermission
method is called with an
AWTPermission("listenToAllAWTEvents") permission.
This may result in a SecurityException.
Listeners can be returned
within AWTEventListenerProxy objects, which also contain
the event mask for the given listener.
Note that listener objects
added multiple times appear only once in the returned array.
| ||||||||||||||||||||
| public Dimension | getBestCursorSize(int preferredWidth, int preferredHeight) throws HeadlessException Details
Returns the supported cursor dimension which is closest to the desired
sizes. Systems which only support a single cursor size will return that
size regardless of the desired sizes. Systems which don't support custom
cursors will return a dimension of 0, 0. Note: if an image is used whose dimensions don't match a supported size (as returned by this method), the Toolkit implementation will attempt to resize the image to a supported size. Since converting low-resolution images is difficult, no guarantees are made as to the quality of a cursor image which isn't a supported size. It is therefore recommended that this method be called and an appropriate image used so no image conversion is made.
| ||||||||||||||||||||
| abstract public ColorModel | getColorModel() throws HeadlessException Details
Determines the color model of this toolkit's screen.
This toolkit method is called by the
| ||||||||||||||||||||
| public static Toolkit | getDefaultToolkit() Details
Gets the default toolkit.
If a system property named
If there is no Also loads additional classes into the VM, using the property 'assistive_technologies' specified in the Sun reference implementation by a line in the 'accessibility.properties' file. The form is "assistive_technologies=..." where the "..." is a comma-separated list of assistive technology classes to load. Each class is loaded in the order given and a single instance of each is created using Class.forName(class).newInstance(). This is done just after the AWT toolkit is created. All errors are handled via an AWTError exception.
| ||||||||||||||||||||
| final protected void | setDesktopProperty(String name, Object 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. | ||||||||||||||||||||
| final public Object | getDesktopProperty(String propertyName) Obtains a value for the specified desktop property. A desktop property is a uniquely named value for a resource that is Toolkit global in nature. Usually it also is an abstract representation for an underlying platform dependent desktop setting. For more information on desktop properties supported by the AWT see AWT Desktop Properties. | ||||||||||||||||||||
| public void | setDynamicLayout(boolean dynamic) throws HeadlessException Details
Controls whether the layout of Containers is validated dynamically
during resizing, or statically, after resizing is complete.
Note that this feature is not supported on all platforms, and
conversely, that this feature cannot be turned off on some platforms.
On platforms where dynamic layout during resize is not supported
(or is always supported), setting this property has no effect.
Note that this feature can be set or unset as a property of the
operating system or window manager on some platforms. On such
platforms, the dynamic resize property must be set at the operating
system or window manager level before this method can take effect.
This method does not change the underlying operating system or
window manager support or settings. The OS/WM support can be
queried using getDesktopProperty("awt.dynamicLayoutSupported").
| ||||||||||||||||||||
| public boolean | isDynamicLayoutActive() throws HeadlessException Details
Returns whether dynamic layout of Containers on resize is
currently active (both set programmatically, and supported
by the underlying operating system and/or window manager).
The OS/WM support can be queried using
getDesktopProperty("awt.dynamicLayoutSupported").
| ||||||||||||||||||||
| protected boolean | isDynamicLayoutSet() throws HeadlessException Details
Returns whether the layout of Containers is validated dynamically
during resizing, or statically, after resizing is complete.
Note: this method returns the value that was set programmatically;
it does not reflect support at the level of the operating system
or window manager for dynamic layout on resizing, or the current
operating system or window manager settings. The OS/WM support can
be queried using getDesktopProperty("awt.dynamicLayoutSupported").
| ||||||||||||||||||||
| abstract public String[] | getFontList() Details
Returns the names of the available fonts in this toolkit. For 1.1, the following font names are deprecated (the replacement name follows):
The ZapfDingbats fontname is also deprecated in 1.1 but the characters are defined in Unicode starting at 0x2700, and as of 1.1 Java supports those characters.
| ||||||||||||||||||||
| abstract public FontMetrics | getFontMetrics(Font font) Details
Gets the screen device metrics for rendering of the font.
| ||||||||||||||||||||
| abstract protected FontPeer | getFontPeer(String name, int style) Details
Creates this toolkit's implementation of Font using
the specified peer interface.
| ||||||||||||||||||||
| public boolean | isFrameStateSupported(int state) throws HeadlessException Details
Returns whether Toolkit supports this state for
Frames. This method tells whether the UI
concept of, say, maximization or iconification is
supported. It will always return false for "compound" states
like Frame.ICONIFIED|Frame.MAXIMIZED_VERT.
In other words, the rule of thumb is that only queries with a
single frame state constant as an argument are meaningful.
| ||||||||||||||||||||
| abstract public Image | getImage(String filename) Details
Returns an image which gets pixel data from the specified file,
whose format can be either GIF, JPEG or PNG.
The underlying toolkit attempts to resolve multiple requests
with the same filename to the same returned Image.
Since the mechanism required to facilitate this sharing of
This method first checks if there is a security manager installed.
If so, the method calls the security manager's
| ||||||||||||||||||||
| abstract public Image | getImage(URL url) Details
Returns an image which gets pixel data from the specified URL.
The pixel data referenced by the specified URL must be in one
of the following formats: GIF, JPEG or PNG.
The underlying toolkit attempts to resolve multiple requests
with the same URL to the same returned Image.
Since the mechanism required to facilitate this sharing of
This method first checks if there is a security manager installed.
If so, the method calls the security manager's
| ||||||||||||||||||||
| public void | setLockingKeyState(int keyCode, boolean on) throws UnsupportedOperationException Details
Sets the state of the given locking key on the keyboard.
Valid key codes are
VK_CAPS_LOCK,
VK_NUM_LOCK,
VK_SCROLL_LOCK, and
VK_KANA_LOCK.
Depending on the platform, setting the state of a locking key may involve event processing and therefore may not be immediately observable through getLockingKeyState.
| ||||||||||||||||||||
| public boolean | getLockingKeyState(int keyCode) throws UnsupportedOperationException Details
Returns whether the given locking key on the keyboard is currently in
its "on" state.
Valid key codes are
VK_CAPS_LOCK,
VK_NUM_LOCK,
VK_SCROLL_LOCK, and
VK_KANA_LOCK.
| ||||||||||||||||||||
| public int | getMaximumCursorColors() throws HeadlessException Details
Returns the maximum number of colors the Toolkit supports in a custom cursor
palette. Note: if an image is used which has more colors in its palette than the supported maximum, the Toolkit implementation will attempt to flatten the palette to the maximum. Since converting low-resolution images is difficult, no guarantees are made as to the quality of a cursor image which has more colors than the system supports. It is therefore recommended that this method be called and an appropriate image used so no image conversion is made.
| ||||||||||||||||||||
| public int | getMenuShortcutKeyMask() throws HeadlessException Details
Determines which modifier key is the appropriate accelerator
key for menu shortcuts.
Menu shortcuts, which are embodied in the
By default, this method returns
| ||||||||||||||||||||
| abstract public boolean | isModalExclusionTypeSupported(Dialog.ModalExclusionType modalExclusionType) Details
Returns whether the given modal exclusion type is supported by this
toolkit. If an unsupported modal exclusion type property is set on a window,
then Dialog.ModalExclusionType.NO_EXCLUDE is used instead.
| ||||||||||||||||||||
| abstract public boolean | isModalityTypeSupported(Dialog.ModalityType modalityType) Details
Returns whether the given modality type is supported by this toolkit. If
a dialog with unsupported modality type is created, then
Dialog.ModalityType.MODELESS is used instead.
| ||||||||||||||||||||
| protected MouseInfoPeer | getMouseInfoPeer() Details
Obtains this toolkit's implementation of helper class for
MouseInfo operations.
| ||||||||||||||||||||
| protected static Container | getNativeContainer(Component c) Give native peers the ability to query the native container given a native component (eg the direct parent may be lightweight). | ||||||||||||||||||||
| abstract public PrintJob | getPrintJob(Frame frame, String jobtitle, Properties props) Details
Gets a PrintJob object which is the result of initiating
a print operation on the toolkit's platform.
Each actual implementation of this method should first check if there
is a security manager installed. If there is, the method should call
the security manager's
| ||||||||||||||||||||
| public PrintJob | getPrintJob(Frame frame, String jobtitle, JobAttributes jobAttributes, PageAttributes pageAttributes) Details
Gets a PrintJob object which is the result of initiating
a print operation on the toolkit's platform.
Each actual implementation of this method should first check if there
is a security manager installed. If there is, the method should call
the security manager's
| ||||||||||||||||||||
| public static String | getProperty(String key, String defaultValue) Gets a property with the specified key and default. This method returns defaultValue if the property is not found. | ||||||||||||||||||||
| public PropertyChangeListener[] | getPropertyChangeListeners() Details
Returns an array of all the property change listeners
registered on this toolkit.
| ||||||||||||||||||||
| public PropertyChangeListener[] | getPropertyChangeListeners(String propertyName) Details
Returns an array of all the PropertyChangeListeners
associated with the named property.
| ||||||||||||||||||||
| public Insets | getScreenInsets(GraphicsConfiguration gc) throws HeadlessException Details
Gets the insets of the screen.
| ||||||||||||||||||||
| abstract public int | getScreenResolution() throws HeadlessException Details
Returns the screen resolution in dots-per-inch.
| ||||||||||||||||||||
| abstract public Dimension | getScreenSize() throws HeadlessException Details
Gets the size of the screen. On systems with multiple displays, the
primary display is used. Multi-screen aware display dimensions are
available from GraphicsConfiguration and
GraphicsDevice.
| ||||||||||||||||||||
| abstract public Clipboard | getSystemClipboard() throws HeadlessException Details
Gets the singleton instance of the system Clipboard which interfaces
with clipboard facilities provided by the native platform. This
clipboard enables data transfer between Java programs and native
applications which use native clipboard facilities.
In addition to any and all formats specified in the flavormap.properties
file, or other file specified by the
java.awt.datatransfer.StringSelection, if the
requested flavor is DataFlavor.plainTextFlavor, or an
equivalent flavor, a Reader is returned. Note: The behavior of
the system Clipboard's getTransferData() method for
DataFlavor.plainTextFlavor, and equivalent DataFlavors, is
inconsistent with the definition of DataFlavor.plainTextFlavor
. Because of this, support for
DataFlavor.plainTextFlavor, and equivalent flavors, is
deprecated.
Each actual implementation of this method should first check if there
is a security manager installed. If there is, the method should call
the security manager's
| ||||||||||||||||||||
| final public EventQueue | getSystemEventQueue() Details
Get the application's or applet's EventQueue instance.
Depending on the Toolkit implementation, different EventQueues
may be returned for different applets. Applets should
therefore not assume that the EventQueue instance returned
by this method will be shared by other applets or the system.
First, if there is a security manager, its
| ||||||||||||||||||||
| abstract protected EventQueue | getSystemEventQueueImpl() Details
Gets the application's or applet's EventQueue
instance, without checking access. For security reasons,
this can only be called from a Toolkit subclass.
| ||||||||||||||||||||
| public Clipboard | getSystemSelection() throws HeadlessException Details
Gets the singleton instance of the system selection as a
Clipboard object. This allows an application to read and
modify the current, system-wide selection.
An application is responsible for updating the system selection whenever
the user selects text, using either the mouse or the keyboard.
Typically, this is implemented by installing a
Some platforms do not support a system selection
Each actual implementation of this method should first check if there
is a
| ||||||||||||||||||||
| About DocWeb · Bundles · Export · Export All | Top 10 · Statistics · Login |
| About Sun · Contact · Privacy · Terms of Use · Trademarks | Java SE 6 · Copyright © 1994-2013 Sun Microsystems, Inc.All rights reserved. Use is subject to license terms |
![]() |
![]() |
|