public abstract class

EmbeddedFrame

extends Frame
implements KeyEventDispatcher PropertyChangeListener
java.lang.Object
   ↳ java.awt.Component
     ↳ java.awt.Container
       ↳ java.awt.Window
         ↳ java.awt.Frame
           ↳ sun.awt.EmbeddedFrame

Class Overview

A generic container used for embedding Java components, usually applets. An EmbeddedFrame has two related uses: . Within a Java-based application, an EmbeddedFrame serves as a sort of firewall, preventing the contained components or applets from using getParent() to find parent components, such as menubars. . Within a C-based application, an EmbeddedFrame contains a window handle which was created by the application, which serves as the top-level Java window. EmbeddedFrames created for this purpose are passed-in a handle of an existing window created by the application. The window handle should be of the appropriate native type for a specific platform, as stored in the pData field of the ComponentPeer.

Summary

Constants
boolean BACKWARD
boolean FORWARD
[Expand]
Inherited Constants
From class java.awt.Frame
From class java.awt.Component
From interface java.awt.image.ImageObserver
Protected Constructors
EmbeddedFrame(boolean supportsXEmbed)
EmbeddedFrame()
EmbeddedFrame(int handle)
This constructor is deprecated. This constructor will be removed in 1.5
EmbeddedFrame(long handle)
EmbeddedFrame(long handle, boolean supportsXEmbed)
Public Methods
void addNotify()
Makes this Frame displayable by connecting it to a native screen resource.
boolean dispatchKeyEvent(KeyEvent e)
Need this method to detect when the focus may have chance to leave the focus cycle root which is EmbeddedFrame.
static Applet getAppletIfAncestorOf(Component comp)
Checks if the component is in an EmbeddedFrame.
Cursor getCursor()
Gets the cursor set in the component.
Container getParent()
Block introspection of a parent window by this child.
void hide()
This method is deprecated. As of JDK version 1.5, replaced by setVisible(boolean).
boolean isCursorAllowed()
boolean isResizable()
Indicates whether this frame is resizable by the user.
void notifyModalBlocked(Dialog blocker, boolean blocked)
This method should be overriden in subclasses.
void propertyChange(PropertyChangeEvent evt)
Needed to track which KeyboardFocusManager is current.
abstract void registerAccelerator(AWTKeyStroke stroke)
void registerListeners()
Because there may be many AppContexts, and we can't be sure where this EmbeddedFrame is first created or shown, we can't automatically determine the correct KeyboardFocusManager to attach to as KeyEventDispatcher.
void remove(MenuComponent m)
Removes the specified menu bar from this frame.
void setCursorAllowed(boolean isCursorAllowed)
void setIconImage(Image image)
Sets the image to be displayed as the icon for this window.
void setIconImages(List<? extends Image> icons)
Sets the sequence of images to be displayed as the icon for this window.
void setMenuBar(MenuBar mb)
Sets the menu bar for this frame to the specified menu bar.
void setResizable(boolean resizable)
Sets whether this frame is resizable by the user.
void setTitle(String title)
Block modifying any frame attributes, since they aren't applicable for EmbeddedFrames.
void show()
This method is deprecated. As of JDK version 1.5, replaced by setVisible(boolean).
boolean supportsXEmbed()
void synthesizeWindowActivation(boolean doActivate)
Synthesize native message to activate or deactivate EmbeddedFrame window depending on the value of parameter b.
void toBack()
If this Window is visible, sends this Window to the back and may cause it to lose focus or activation if it is the focused or active Window.
void toFront()
If this Window is visible, brings this Window to the front and may make it the focused Window.
abstract void unregisterAccelerator(AWTKeyStroke stroke)
Protected Methods
Rectangle getBoundsPrivate()
Gets the bounds of this embedded frame as a rectangle specifying the width, height and location relative to the native parent component.
Point getLocationPrivate()
Gets the location of this embedded frame as a point specifying the top-left corner relative to parent component.
void setBoundsPrivate(int x, int y, int width, int height)
Moves and resizes this embedded frame.
void setLocationPrivate(int x, int y)
Moves this embedded frame to a new location.
void setPeer(ComponentPeer p)
boolean traverseOut(boolean direction)
This method is called from dispatchKeyEvent in the following two cases: 1.
[Expand]
Inherited Methods
From class java.awt.Frame
From class java.awt.Window
From class java.awt.Container
From class java.awt.Component
From class java.lang.Object
From interface java.awt.KeyEventDispatcher
From interface java.awt.MenuContainer
From interface java.awt.image.ImageObserver
From interface java.beans.PropertyChangeListener
From interface javax.accessibility.Accessible

Constants

protected static final boolean BACKWARD

Constant Value: false

protected static final boolean FORWARD

Constant Value: true

Protected Constructors

protected EmbeddedFrame (boolean supportsXEmbed)

protected EmbeddedFrame ()

protected EmbeddedFrame (int handle)

This constructor is deprecated.
This constructor will be removed in 1.5

protected EmbeddedFrame (long handle)

protected EmbeddedFrame (long handle, boolean supportsXEmbed)

Public Methods

public void addNotify ()

Makes this Frame displayable by connecting it to a native screen resource. Making a frame displayable will cause any of its children to be made displayable. This method is called internally by the toolkit and should not be called directly by programs.

public boolean dispatchKeyEvent (KeyEvent e)

Need this method to detect when the focus may have chance to leave the focus cycle root which is EmbeddedFrame. Mostly, the code here is copied from DefaultKeyboardFocusManager.processKeyEvent with some minor modifications.

Parameters
e the KeyEvent to dispatch
Returns
  • true if the KeyboardFocusManager should take no further action with regard to the KeyEvent; false otherwise

public static Applet getAppletIfAncestorOf (Component comp)

Checks if the component is in an EmbeddedFrame. If so, returns the applet found in the hierarchy or null if not found.

Returns
  • the parent applet or {@ null}

public Cursor getCursor ()

Gets the cursor set in the component. If the component does not have a cursor set, the cursor of its parent is returned. If no cursor is set in the entire hierarchy, Cursor.DEFAULT_CURSOR is returned.

public Container getParent ()

Block introspection of a parent window by this child.

Returns
  • the parent container of this component

public void hide ()

This method is deprecated.
As of JDK version 1.5, replaced by setVisible(boolean).

Needed to avoid memory leak: we register this EmbeddedFrame as a listener with KeyboardFocusManager of applet's AppContext. We don't want the KFM to keep reference to our EmbeddedFrame forever if the Frame is no longer in use, so we add listeners in show() and remove them in hide().

public boolean isCursorAllowed ()

public boolean isResizable ()

Indicates whether this frame is resizable by the user. By default, all frames are initially resizable.

Returns
  • true if the user can resize this frame; false otherwise.

public void notifyModalBlocked (Dialog blocker, boolean blocked)

This method should be overriden in subclasses. It is called when window this frame is within should be blocked by some modal dialog.

public void propertyChange (PropertyChangeEvent evt)

Needed to track which KeyboardFocusManager is current. We want to avoid memory leaks, so when KFM stops being current, we remove ourselves as listeners.

Parameters
evt A PropertyChangeEvent object describing the event source and the property that has changed.

public abstract void registerAccelerator (AWTKeyStroke stroke)

public void registerListeners ()

Because there may be many AppContexts, and we can't be sure where this EmbeddedFrame is first created or shown, we can't automatically determine the correct KeyboardFocusManager to attach to as KeyEventDispatcher. Those who want to use the functionality of traversing out of the EmbeddedFrame must call this method on the Applet's AppContext. After that, all the changes can be handled automatically, including possible replacement of KeyboardFocusManager.

public void remove (MenuComponent m)

Removes the specified menu bar from this frame.

Parameters
m the menu component to remove. If m is null, then no action is taken

public void setCursorAllowed (boolean isCursorAllowed)

public void setIconImage (Image image)

Sets the image to be displayed as the icon for this window.

This method can be used instead of setIconImages() to specify a single image as a window's icon.

The following statement:

     setIconImage(image);
 
is equivalent to:
     ArrayList<Image> imageList = new ArrayList<Image>();
     imageList.add(image);
     setIconImages(imageList);
 

Note : Native windowing systems may use different images of differing dimensions to represent a window, depending on the context (e.g. window decoration, window list, taskbar, etc.). They could also use just a single image for all contexts or no image at all.

Parameters
image the icon image to be displayed.

public void setIconImages (List<? extends Image> icons)

Sets the sequence of images to be displayed as the icon for this window. Subsequent calls to getIconImages will always return a copy of the icons list.

Depending on the platform capabilities one or several images of different dimensions will be used as the window's icon.

The icons list is scanned for the images of most appropriate dimensions from the beginning. If the list contains several images of the same size, the first will be used.

Ownerless windows with no icon specified use platfrom-default icon. The icon of an owned window may be inherited from the owner unless explicitly overridden. Setting the icon to null or empty list restores the default behavior.

Note : Native windowing systems may use different images of differing dimensions to represent a window, depending on the context (e.g. window decoration, window list, taskbar, etc.). They could also use just a single image for all contexts or no image at all.

Parameters
icons the list of icon images to be displayed.

public void setMenuBar (MenuBar mb)

Sets the menu bar for this frame to the specified menu bar.

Parameters
mb the menu bar being set. If this parameter is null then any existing menu bar on this frame is removed.

public void setResizable (boolean resizable)

Sets whether this frame is resizable by the user.

Parameters
resizable true if this frame is resizable; false otherwise.

public void setTitle (String title)

Block modifying any frame attributes, since they aren't applicable for EmbeddedFrames.

Parameters
title the title to be displayed in the frame's border. A null value is treated as an empty string, "".

public void show ()

This method is deprecated.
As of JDK version 1.5, replaced by setVisible(boolean).

Needed to avoid memory leak: we register this EmbeddedFrame as a listener with KeyboardFocusManager of applet's AppContext. We don't want the KFM to keep reference to our EmbeddedFrame forever if the Frame is no longer in use, so we add listeners in show() and remove them in hide().

public boolean supportsXEmbed ()

public void synthesizeWindowActivation (boolean doActivate)

Synthesize native message to activate or deactivate EmbeddedFrame window depending on the value of parameter b. Peers should override this method if they are to implement this functionality.

Parameters
doActivate if true, activates the window; otherwise, deactivates the window

public void toBack ()

If this Window is visible, sends this Window to the back and may cause it to lose focus or activation if it is the focused or active Window.

Places this Window at the bottom of the stacking order and shows it behind any other Windows in this VM. No action will take place is this Window is not visible. Some platforms do not allow Windows which are owned by other Windows to appear below their owners. Every attempt will be made to move this Window as low as possible in the stacking order; however, developers should not assume that this method will move this Window below all other windows in every situation.

Because of variations in native windowing systems, no guarantees about changes to the focused and active Windows can be made. Developers must never assume that this Window is no longer the focused or active Window until this Window receives a WINDOW_LOST_FOCUS or WINDOW_DEACTIVATED event. On platforms where the top-most window is the focused window, this method will probably cause this Window to lose focus. In that case, the next highest, focusable Window in this VM will receive focus. On platforms where the stacking order does not typically affect the focused window, this method will probably leave the focused and active Windows unchanged.

public void toFront ()

If this Window is visible, brings this Window to the front and may make it the focused Window.

Places this Window at the top of the stacking order and shows it in front of any other Windows in this VM. No action will take place if this Window is not visible. Some platforms do not allow Windows which own other Windows to appear on top of those owned Windows. Some platforms may not permit this VM to place its Windows above windows of native applications, or Windows of other VMs. This permission may depend on whether a Window in this VM is already focused. Every attempt will be made to move this Window as high as possible in the stacking order; however, developers should not assume that this method will move this Window above all other windows in every situation.

Because of variations in native windowing systems, no guarantees about changes to the focused and active Windows can be made. Developers must never assume that this Window is the focused or active Window until this Window receives a WINDOW_GAINED_FOCUS or WINDOW_ACTIVATED event. On platforms where the top-most window is the focused window, this method will probably focus this Window, if it is not already focused. On platforms where the stacking order does not typically affect the focused window, this method will probably leave the focused and active Windows unchanged.

If this method causes this Window to be focused, and this Window is a Frame or a Dialog, it will also become activated. If this Window is focused, but it is not a Frame or a Dialog, then the first Frame or Dialog that is an owner of this Window will be activated.

If this window is blocked by modal dialog, then the blocking dialog is brought to the front and remains above the blocked window.

public abstract void unregisterAccelerator (AWTKeyStroke stroke)

Protected Methods

protected Rectangle getBoundsPrivate ()

Gets the bounds of this embedded frame as a rectangle specifying the width, height and location relative to the native parent component.

setLocation() and setBounds() for EmbeddedFrame really don't move it within the native parent. These methods always put embedded frame to (0, 0) for backward compatibility. To allow getting location and size of embedded frames getLocationPrivate() and getBoundsPrivate() were introduced, and they work just the same way as getLocation() and getBounds() for ususal, non-embedded components.

Using usual get/setLocation() and get/setBounds() together with new get/setLocationPrivate() and get/setBoundsPrivate() is not recommended. For example, calling getBoundsPrivate() after setLocation() works fine, but getBounds() after setBoundsPrivate() may return unpredictable value.

Returns
  • a rectangle indicating this embedded frame's bounds

protected Point getLocationPrivate ()

Gets the location of this embedded frame as a point specifying the top-left corner relative to parent component.

setLocation() and setBounds() for EmbeddedFrame really don't move it within the native parent. These methods always put embedded frame to (0, 0) for backward compatibility. To allow getting location and size of embedded frame getLocationPrivate() and getBoundsPrivate() were introduced, and they work just the same way as getLocation() and getBounds() for ususal, non-embedded components.

Using usual get/setLocation() and get/setBounds() together with new get/setLocationPrivate() and get/setBoundsPrivate() is not recommended. For example, calling getBoundsPrivate() after setLocation() works fine, but getBounds() after setBoundsPrivate() may return unpredictable value.

Returns
  • a point indicating this embedded frame's top-left corner

protected void setBoundsPrivate (int x, int y, int width, int height)

Moves and resizes this embedded frame. The new location of the top-left corner is specified by x and y parameters relative to the native parent component. The new size is specified by width and height.

setLocation() and setBounds() for EmbeddedFrame really don't move it within the native parent. These methods always put embedded frame to (0, 0) for backward compatibility. To allow moving embedded frames setLocationPrivate() and setBoundsPrivate() were introduced, and they work just the same way as setLocation() and setBounds() for usual, non-embedded components.

Using usual get/setLocation() and get/setBounds() together with new get/setLocationPrivate() and get/setBoundsPrivate() is not recommended. For example, calling getBoundsPrivate() after setLocation() works fine, but getBounds() after setBoundsPrivate() may return unpredictable value.

Parameters
x the new x-coordinate relative to the parent component
y the new y-coordinate relative to the parent component
width the new width of this embedded frame
height the new height of this embedded frame

protected void setLocationPrivate (int x, int y)

Moves this embedded frame to a new location. The top-left corner of the new location is specified by the x and y parameters relative to the native parent component.

setLocation() and setBounds() for EmbeddedFrame really don't move it within the native parent. These methods always put embedded frame to (0, 0) for backward compatibility. To allow moving embedded frame setLocationPrivate() and setBoundsPrivate() were introduced, and they work just the same way as setLocation() and setBounds() for usual, non-embedded components.

Using usual get/setLocation() and get/setBounds() together with new get/setLocationPrivate() and get/setBoundsPrivate() is not recommended. For example, calling getBoundsPrivate() after setLocation() works fine, but getBounds() after setBoundsPrivate() may return unpredictable value.

Parameters
x the new x-coordinate relative to the parent component
y the new y-coordinate relative to the parent component

protected void setPeer (ComponentPeer p)

protected boolean traverseOut (boolean direction)

This method is called from dispatchKeyEvent in the following two cases: 1. The focus is on the first Component of this EmbeddedFrame and we are about to transfer the focus backward. 2. The focus in on the last Component of this EmbeddedFrame and we are about to transfer the focus forward. This is needed to give the opportuity for keyboard focus to leave the EmbeddedFrame. Override this method, initiate focus transfer in it and return true if you want the focus to leave EmbeddedFrame's cycle. The direction parameter specifies which of the two mentioned cases is happening. Use FORWARD and BACKWARD constants defined in EmbeddedFrame to avoid confusing boolean values.

Parameters
direction FORWARD or BACKWARD
Returns
  • true, if EmbeddedFrame wants the focus to leave it, false otherwise.