APIdia Launch Partner
Top Description Fields Methods
java.awt.peer

public Interface ComponentPeer

Known Direct Subinterfaces
java.awt.peer.ContainerPeer, java.awt.peer.LabelPeer, java.awt.peer.LightweightPeer, java.awt.peer.ListPeer, java.awt.peer.ScrollbarPeer, java.awt.peer.TextComponentPeer, java.awt.peer.ButtonPeer, java.awt.peer.CanvasPeer, java.awt.peer.CheckboxPeer, java.awt.peer.ChoicePeer
Known Direct Implementers
sun.awt.X11.XComponentPeer, sun.awt.X11.XEmbedChildProxyPeer
Imports
java.awt.AWTEvent, .AWTException, .BufferCapabilities, .Color, .Component, .Dimension, .EventQueue, .Font, .FontMetrics, .Graphics, .GraphicsConfiguration, .Image, .Point, java.awt.event.FocusEvent.Cause, .PaintEvent, java.awt.image.ColorModel, .VolatileImage, sun.java2d.pipe.Region

The peer interface for Component. This is the top level peer interface for widgets and defines the bulk of methods for AWT component peers. Most component peers have to implement this interface (via one of the subinterfaces), except menu components, which implement MenuComponentPeer. The peer interfaces are intended only for use in porting the AWT. They are not intended for use by application developers, and developers should not implement peers nor invoke any of the peer methods directly on the peer instances.

Field Summary

Modifier and TypeField and Description
public static final int
DEFAULT_OPERATION

The default operation, which is to set size and location.

public static final int
NO_EMBEDDED_CHECK

A flag that is used to suppress checks for embedded frames.

public static final int
RESET_OPERATION

Resets the setBounds() operation to DEFAULT_OPERATION.

public static final int
SET_BOUNDS

Operation for setBounds(int, int, int, int, int), indicating a change in the component size and location.

public static final int
SET_CLIENT_SIZE

Operation for setBounds(int, int, int, int, int), indicating a change in the component client size.

public static final int
SET_LOCATION

Operation for setBounds(int, int, int, int, int), indicating a change in the component location only.

public static final int
SET_SIZE

Operation for setBounds(int, int, int, int, int), indicating a change in the component size only.

Method Summary

Modifier and TypeMethod and Description
public void
applyShape(Region
the shape to apply
shape
)

Applies the shape to the native component window.

public boolean

Returns:

true when the peer can determine if a component has been obscured, false false otherwise
canDetermineObscurity
()

Returns true when the peer can determine if a component has been obscured, false false otherwise.

public void
coalescePaintEvent(PaintEvent
the paint event to consider to coalesce
e
)

Called to coalesce paint events.

public void
createBuffers(int
the number of buffers to create
numBuffers
,
BufferCapabilities
the buffer capabilities
caps
)

Create numBuffers flipping buffers with the specified buffer capabilities.

public Image

Returns:

the created image
createImage
(int
the width of the image
width
,
int
the height of the image
height
)

Creates an empty image with the specified width and height.

public VolatileImage

Returns:

the created volatile image
createVolatileImage
(int
the width of the image
width
,
int
the height of the image
height
)

Creates an empty volatile image with the specified width and height.

public void
destroyBuffers()

Destroys all created buffers.

public void
dispose()

Disposes all resources held by the component peer.

public void
flip(int
the area to be flipped, upper left X coordinate
x1
,
int
the area to be flipped, upper left Y coordinate
y1
,
int
the area to be flipped, lower right X coordinate
x2
,
int
the area to be flipped, lower right Y coordinate
y2
,
BufferCapabilities.FlipContents
the flip action to perform
flipAction
)

Move the back buffer to the front buffer.

public Image

Returns:

the back buffer as image
getBackBuffer
()

Returns the back buffer as image.

public ColorModel

Returns:

the color model used by the component
getColorModel
()

Returns the color model used by the component.

public FontMetrics

Returns:

a font metrics object to determine the metrics properties of the specified font
getFontMetrics
(Font
the font to determine the metrics for
font
)

Returns a font metrics object to determine the metrics properties of the specified font.

public Graphics

Returns:

a graphics object to paint on the component
getGraphics
()

Returns a graphics object to paint on the component.

public GraphicsConfiguration

Returns:

the graphics configuration that corresponds to this component
getGraphicsConfiguration
()

Returns the graphics configuration that corresponds to this component.

public Point

Returns:

the location of the component on the screen
getLocationOnScreen
()

Determines the location of the component on the screen.

public Dimension

Returns:

the minimum size of the component
getMinimumSize
()

Determines the minimum size of the component.

public Dimension

Returns:

the preferred size of the component
getPreferredSize
()

Determines the preferred size of the component.

public void
handleEvent(AWTEvent
the AWT event to handle
e
)

Called to let the component peer handle events.

public boolean

Returns:

true if the component handles wheel scrolling, false otherwise
handlesWheelScrolling
()

Determines if the component handles wheel scrolling itself.

public boolean

Returns:

true when the component takes part in the focus traversal, false otherwise
isFocusable
()

Returns true when the component takes part in the focus traversal, false otherwise.

public boolean

Returns:

true when the component has been obscured, false otherwise
isObscured
()

Determines if a component has been obscured, i.e. by an overlapping window or similar.

public boolean

Returns:

true if appropriate reparent is supported, false otherwise
isReparentSupported
()

Returns whether this peer supports reparenting to another parent without destroying the peer.

public void
layout()

Used by lightweight implementations to tell a ComponentPeer to layout its sub-elements.

public void
paint(Graphics
the graphics context to paint to
g
)

Paints the component to the specified graphics context.

public void
reparent(ContainerPeer
peer of the new parent container
newContainer
)

Reparents this peer to the new parent referenced by newContainer peer.

public boolean

Returns:

true if the focus change is guaranteed to be granted, false otherwise
requestFocus
(Component
the actual lightweight child that requests the focus
lightweightChild
,
boolean
true if the focus change is temporary, false otherwise
temporary
,
boolean
true if changing the focus of the containing window is allowed or not
focusedWindowChangeAllowed
,
long
the time of the focus change request
time
,
FocusEvent.Cause
the cause of the focus change request
cause
)

Requests focus on this component.

public void
setBackground(Color
the background color to set
c
)

Sets the background color of this component.

public void
setBounds(int
the X location of the component
x
,
int
the Y location of the component
y
,
int
the width of the component
width
,
int
the height of the component
height
,
int
the operation flag
op
)

Sets the location or size or both of the component.

public void
setEnabled(boolean
true to enable the component, false to disable it
e
)

Enables or disables a component.

public void
setFont(Font
the font of this component
f
)

Sets the font of this component.

public void
setForeground(Color
the foreground color to set
c
)

Sets the foreground color of this component.

public void
setVisible(boolean
true to make a component visible, false to make it invisible
v
)

Makes a component visible or invisible.

public void
setZOrder(ComponentPeer
the peer to lower this component with respect to
above
)

Lowers this component at the bottom of the above HW peer.

public void
updateCursorImmediately()

Updates the cursor of the component.

public boolean

Returns:

true if the peer needs to be recreated for the changes to take effect, otherwise false
updateGraphicsData
(GraphicsConfiguration
the reference graphics configuration
gc
)

Updates internal data structures related to the component's GC.

Field Detail

DEFAULT_OPERATIONback to summary
public static final int DEFAULT_OPERATION

The default operation, which is to set size and location.

Todo

This is only used internally and should probably be moved outside the peer interface.

See Also
Component#setBoundsOp
NO_EMBEDDED_CHECKback to summary
public static final int NO_EMBEDDED_CHECK

A flag that is used to suppress checks for embedded frames.

Todo

This is only used internally and should probably be moved outside the peer interface.

RESET_OPERATIONback to summary
public static final int RESET_OPERATION

Resets the setBounds() operation to DEFAULT_OPERATION. This is not passed into setBounds(int, int, int, int, int).

Todo

This is only used internally and should probably be moved outside the peer interface.

See Also
Component#setBoundsOp
SET_BOUNDSback to summary
public static final int SET_BOUNDS

Operation for setBounds(int, int, int, int, int), indicating a change in the component size and location.

See Also
setBounds(int, int, int, int, int)
SET_CLIENT_SIZEback to summary
public static final int SET_CLIENT_SIZE

Operation for setBounds(int, int, int, int, int), indicating a change in the component client size. This is used for setting the 'inside' size of windows, without the border insets.

See Also
setBounds(int, int, int, int, int)
SET_LOCATIONback to summary
public static final int SET_LOCATION

Operation for setBounds(int, int, int, int, int), indicating a change in the component location only.

See Also
setBounds(int, int, int, int, int)
SET_SIZEback to summary
public static final int SET_SIZE

Operation for setBounds(int, int, int, int, int), indicating a change in the component size only.

See Also
setBounds(int, int, int, int, int)

Method Detail

applyShapeback to summary
public void applyShape(Region shape)

Applies the shape to the native component window.

Parameters
shape:Region

the shape to apply

Since
1.7
See Also
Component#applyCompoundShape
canDetermineObscurityback to summary
public boolean canDetermineObscurity()

Returns true when the peer can determine if a component has been obscured, false false otherwise.

Returns:boolean

true when the peer can determine if a component has been obscured, false false otherwise

See Also
isObscured(), javax.swing.JViewport#needsRepaintAfterBlit
coalescePaintEventback to summary
public void coalescePaintEvent(PaintEvent e)

Called to coalesce paint events.

Parameters
e:PaintEvent

the paint event to consider to coalesce

See Also
EventQueue#coalescePaintEvent
createBuffersback to summary
public void createBuffers(int numBuffers, BufferCapabilities caps) throws AWTException

Create numBuffers flipping buffers with the specified buffer capabilities.

Parameters
numBuffers:int

the number of buffers to create

caps:BufferCapabilities

the buffer capabilities

Exceptions
AWTException:
if flip buffering is not supported
createImageback to summary
public Image createImage(int width, int height)

Creates an empty image with the specified width and height. This is generally used as a non-accelerated backbuffer for drawing onto the component (e.g. by Swing).

Parameters
width:int

the width of the image

height:int

the height of the image

Returns:Image

the created image

See Also
Component#createImage(int, int)
createVolatileImageback to summary
public VolatileImage createVolatileImage(int width, int height)

Creates an empty volatile image with the specified width and height. This is generally used as an accelerated backbuffer for drawing onto the component (e.g. by Swing).

Parameters
width:int

the width of the image

height:int

the height of the image

Returns:VolatileImage

the created volatile image

See Also
Component#createVolatileImage(int, int)
destroyBuffersback to summary
public void destroyBuffers()

Destroys all created buffers.

disposeback to summary
public void dispose()

Disposes all resources held by the component peer. This is called when the component has been disconnected from the component hierarchy and is about to be garbage collected.

See Also
Component#removeNotify()
flipback to summary
public void flip(int x1, int y1, int x2, int y2, BufferCapabilities.FlipContents flipAction)

Move the back buffer to the front buffer.

Parameters
x1:int

the area to be flipped, upper left X coordinate

y1:int

the area to be flipped, upper left Y coordinate

x2:int

the area to be flipped, lower right X coordinate

y2:int

the area to be flipped, lower right Y coordinate

flipAction:BufferCapabilities.FlipContents

the flip action to perform

getBackBufferback to summary
public Image getBackBuffer()

Returns the back buffer as image.

Returns:Image

the back buffer as image

getColorModelback to summary
public ColorModel getColorModel()

Returns the color model used by the component.

Returns:ColorModel

the color model used by the component

See Also
Component#getColorModel()
getFontMetricsback to summary
public FontMetrics getFontMetrics(Font font)

Returns a font metrics object to determine the metrics properties of the specified font.

Parameters
font:Font

the font to determine the metrics for

Returns:FontMetrics

a font metrics object to determine the metrics properties of the specified font

See Also
Component#getFontMetrics(Font)
getGraphicsback to summary
public Graphics getGraphics()

Returns a graphics object to paint on the component.

Returns:Graphics

a graphics object to paint on the component

See Also
Component#getGraphics()
getGraphicsConfigurationback to summary
public GraphicsConfiguration getGraphicsConfiguration()

Returns the graphics configuration that corresponds to this component.

Returns:GraphicsConfiguration

the graphics configuration that corresponds to this component

See Also
Component#getGraphicsConfiguration()
getLocationOnScreenback to summary
public Point getLocationOnScreen()

Determines the location of the component on the screen.

Returns:Point

the location of the component on the screen

See Also
Component#getLocationOnScreen()
getMinimumSizeback to summary
public Dimension getMinimumSize()

Determines the minimum size of the component.

Returns:Dimension

the minimum size of the component

See Also
Component#getMinimumSize()
getPreferredSizeback to summary
public Dimension getPreferredSize()

Determines the preferred size of the component.

Returns:Dimension

the preferred size of the component

See Also
Component#getPreferredSize()
handleEventback to summary
public void handleEvent(AWTEvent e)

Called to let the component peer handle events.

Parameters
e:AWTEvent

the AWT event to handle

See Also
Component#dispatchEvent(AWTEvent)
handlesWheelScrollingback to summary
public boolean handlesWheelScrolling()

Determines if the component handles wheel scrolling itself. Otherwise it is delegated to the component's parent.

Returns:boolean

true if the component handles wheel scrolling, false otherwise

See Also
Component#dispatchEventImpl(AWTEvent)
isFocusableback to summary
public boolean isFocusable()

Returns true when the component takes part in the focus traversal, false otherwise.

Returns:boolean

true when the component takes part in the focus traversal, false otherwise

isObscuredback to summary
public boolean isObscured()

Determines if a component has been obscured, i.e. by an overlapping window or similar. This is used by JViewport for optimizing performance. This doesn't have to be implemented, when canDetermineObscurity() returns false.

Returns:boolean

true when the component has been obscured, false otherwise

See Also
canDetermineObscurity(), javax.swing.JViewport#needsRepaintAfterBlit
isReparentSupportedback to summary
public boolean isReparentSupported()

Returns whether this peer supports reparenting to another parent without destroying the peer.

Returns:boolean

true if appropriate reparent is supported, false otherwise

Since
1.5
layoutback to summary
public void layout()

Used by lightweight implementations to tell a ComponentPeer to layout its sub-elements. For instance, a lightweight Checkbox needs to layout the box, as well as the text label.

See Also
Component#validate()
paintback to summary
public void paint(Graphics g)

Paints the component to the specified graphics context. This is called by Component#paintAll(Graphics) to paint the component.

Parameters
g:Graphics

the graphics context to paint to

See Also
Component#paintAll(Graphics)
reparentback to summary
public void reparent(ContainerPeer newContainer)

Reparents this peer to the new parent referenced by newContainer peer. Implementation depends on toolkit and container.

Parameters
newContainer:ContainerPeer

peer of the new parent container

Since
1.5
requestFocusback to summary
public boolean requestFocus(Component lightweightChild, boolean temporary, boolean focusedWindowChangeAllowed, long time, FocusEvent.Cause cause)

Requests focus on this component.

Parameters
lightweightChild:Component

the actual lightweight child that requests the focus

temporary:boolean

true if the focus change is temporary, false otherwise

focusedWindowChangeAllowed:boolean

true if changing the focus of the containing window is allowed or not

time:long

the time of the focus change request

cause:FocusEvent.Cause

the cause of the focus change request

Returns:boolean

true if the focus change is guaranteed to be granted, false otherwise

setBackgroundback to summary
public void setBackground(Color c)

Sets the background color of this component.

Parameters
c:Color

the background color to set

See Also
Component#setBackground(Color)
setBoundsback to summary
public void setBounds(int x, int y, int width, int height, int op)

Sets the location or size or both of the component. The location is specified relative to the component's parent. The op parameter specifies which properties change. If it is SET_LOCATION, then only the location changes (and the size parameters can be ignored). If op is SET_SIZE, then only the size changes (and the location can be ignored). If op is SET_BOUNDS, then both change. There is a special value SET_CLIENT_SIZE, which is used only for window-like components to set the size of the client (i.e. the 'inner' size, without the insets of the window borders).

Parameters
x:int

the X location of the component

y:int

the Y location of the component

width:int

the width of the component

height:int

the height of the component

op:int

the operation flag

See Also
SET_BOUNDS, SET_LOCATION, SET_SIZE, SET_CLIENT_SIZE
setEnabledback to summary
public void setEnabled(boolean e)

Enables or disables a component. Disabled components are usually grayed out and cannot be activated.

Parameters
e:boolean

true to enable the component, false to disable it

See Also
Component#setEnabled(boolean)
setFontback to summary
public void setFont(Font f)

Sets the font of this component.

Parameters
f:Font

the font of this component

See Also
Component#setFont(Font)
setForegroundback to summary
public void setForeground(Color c)

Sets the foreground color of this component.

Parameters
c:Color

the foreground color to set

See Also
Component#setForeground(Color)
setVisibleback to summary
public void setVisible(boolean v)

Makes a component visible or invisible.

Parameters
v:boolean

true to make a component visible, false to make it invisible

See Also
Component#setVisible(boolean)
setZOrderback to summary
public void setZOrder(ComponentPeer above)

Lowers this component at the bottom of the above HW peer. If the above parameter is null then the method places this component at the top of the Z-order.

Parameters
above:ComponentPeer

the peer to lower this component with respect to

updateCursorImmediatelyback to summary
public void updateCursorImmediately()

Updates the cursor of the component.

See Also
Component#updateCursorImmediately
updateGraphicsDataback to summary
public boolean updateGraphicsData(GraphicsConfiguration gc)

Updates internal data structures related to the component's GC.

Parameters
gc:GraphicsConfiguration

the reference graphics configuration

Returns:boolean

true if the peer needs to be recreated for the changes to take effect, otherwise false

Since
1.7