|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.swt.widgets.Widget org.eclipse.swt.widgets.Control org.eclipse.swt.widgets.Scrollable org.eclipse.swt.widgets.Composite swingintegration.example.EmbeddedSwingComposite
public abstract class EmbeddedSwingComposite
A SWT composite widget for embedding Swing components in a SWT composite within an RCP or standalone-SWT application. The Eclipse platform
provides limited support for embedding Swing components through SWT_AWT
.
This class extends that support by
If, rather than embedding Swing components, you are integrating with Swing by opening
Swing dialogs, see the AwtEnvironment
class.
This is an abstract that is normally used by extending it and implementing the createSwingComponent()
method. For example,
embeddedComposite = new EmbeddedSwingComposite(parent, SWT.NONE) { protected JComponent createSwingComponent() { scrollPane = new JScrollPane(); table = new JTable(); scrollPane.setViewportView(table); return scrollPane; } }; embeddedComposite.populate();
The Swing component is created inside a standard Swing containment hierarchy, rooted in
a RootPaneContainer
. The root pane container is placed inside an AWT frame, as
returned by SWT_AWT.new_Frame(Composite)
Note: When you mix components from Swing/AWT and SWT toolkits, there will be two UI event threads, one for AWT, one for SWT. Most SWT APIs require that you call them from the SWT thread. Swing has similar restrictions though it does not enforce them as much as SWT.
Applications need to be aware of the current thread, and, where necessary, schedule tasks to run on another thread. This has always been required in the pure Swing or SWT environments, but when mixing Swing and SWT, more of this scheduling will be necessary.
To schedule work on the AWT event thread, you can use:
(or similar methods in EventQueue
)
To schedule work on the SWT event thread, use:
Of course, as in single-toolkit environments, long-running tasks should be offloaded from either UI thread to a background thread. The Eclipse jobs API can be used for this purpose.
Field Summary |
---|
Fields inherited from class org.eclipse.swt.widgets.Control |
---|
handle |
Constructor Summary | |
---|---|
EmbeddedSwingComposite(Composite parent,
int style)
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance. |
Method Summary | |
---|---|
protected RootPaneContainer |
addRootPaneContainer(Frame frame)
Adds a root pane container to the embedded AWT frame. |
protected abstract JComponent |
createSwingComponent()
Creates the embedded Swing component. |
void |
dispose()
|
boolean |
forceFocus()
|
Frame |
getFrame()
Returns the embedded AWT frame. |
void |
populate()
Populates the embedded composite with the Swing component. |
boolean |
setFocus()
|
protected void |
updateAwtFont(Font newFont)
Performs custom updates to newly set fonts. |
Methods inherited from class org.eclipse.swt.widgets.Composite |
---|
changed, checkSubclass, computeSize, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, setBackgroundMode, setLayout, setLayoutDeferred, setTabList |
Methods inherited from class org.eclipse.swt.widgets.Scrollable |
---|
computeTrim, getClientArea, getHorizontalBar, getVerticalBar |
Methods inherited from class org.eclipse.swt.widgets.Widget |
---|
addDisposeListener, addListener, checkWidget, getData, getData, getDisplay, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, setData, setData, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public EmbeddedSwingComposite(Composite parent, int style)
This method must be called from the SWT event thread.
The style value is either one of the style constants defined in
class SWT
which is applicable to instances of this
class, or must be built by bitwise OR'ing together
(that is, using the int
"|" operator) two or more
of those SWT
style constants. The class description
lists the style constants that are applicable to the class.
Style bits are also inherited from superclasses.
The styles SWT.EMBEDDED and SWT.NO_BACKGROUND will be added to the specified style. Usually, no other style bits are needed.
parent
- a widget which will be the parent of the new instance (cannot be null)style
- the style of widget to construct
IllegalArgumentException
- SWTException
- Widget.getStyle()
Method Detail |
---|
public void populate()
This method must be called from the SWT event thread.
The Swing component will be created by calling createSwingComponent()
. The creation is
scheduled asynchronously on the AWT event thread. This method does not wait for completion of this
asynchronous task, so it may return before createSwingComponent() is complete.
The Swing component is created inside a standard Swing containment hierarchy, rooted in
a RootPaneContainer
. Clients can override addRootPaneContainer(Frame)
to provide their own root pane container implementation.
This method can be called multiple times for a single instance. If an embedded frame exists from a previous call, it is disposed.
SWTException
- protected abstract JComponent createSwingComponent()
Implement this method to provide the Swing component that will be shown inside this composite. The returned component will be added to the Swing content pane. At least one component must be created by this method; null is not a valid return value.
protected RootPaneContainer addRootPaneContainer(Frame frame)
RootPaneContainer
implementation. In most cases, it is not necessary
to override this method.
This method is called from the AWT event thread.
If you are defining your own root pane container, make sure that there is at least one heavyweight (AWT) component in the frame's containment hierarchy; otherwise, event processing will not work correctly. See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4982522 for more information.
frame
- the frame to which the root pane container is added
protected void updateAwtFont(Font newFont)
This method is called from the AWT event thread.
In most cases it is not necessary to override this method. Normally, the implementation of this class will automatically propogate font changes to the embedded Swing components through Swing's Look and Feel support. However, if additional special processing is necessary, it can be done inside this method.
newFont
- New AWT fontpublic Frame getFrame()
public boolean setFocus()
setFocus
in class Composite
public boolean forceFocus()
forceFocus
in class Control
public void dispose()
dispose
in class Widget
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |