Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Running Swing or AWT widgets within SWT.
Running Swing or AWT widgets within SWT. [message #531018] Mon, 03 May 2010 12:08 Go to next message
Uri Shani is currently offline Uri ShaniFriend
Messages: 18
Registered: July 2009
Junior Member
I have an AWT application, which uses a JFrame as top container. I want to hook this app to work from within an SWT Shell - like from a command or an editor.
I know how to get to the Shell of the editor view.
Perhaps I should hook the main Composite component of this JFrame?
Is this possible at all? What is the trick?

Thanks,
- Uri
Re: Running Swing or AWT widgets within SWT. [message #531029 is a reply to message #531018] Mon, 03 May 2010 12:17 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Uri Shani wrote:
> I have an AWT application, which uses a JFrame as top container. I want
> to hook this app to work from within an SWT Shell - like from a command
> or an editor. I know how to get to the Shell of the editor view. Perhaps
> I should hook the main Composite component of this JFrame? Is this
> possible at all? What is the trick?

Check out the SWT_AWT bridge at http://www.eclipse.org/swt/snippets/

you can embed your Swing/AWT components in a Composite, i.e. in a view
or in an editor.

It sounds like you need a heavy-weight component (AWT) as the root and
then add the lightweight components underneath. See
org.eclipse.swt.awt.SWT_AWT.new_Frame(Composite)

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Running Swing or AWT widgets within SWT. [message #531074 is a reply to message #531029] Mon, 03 May 2010 15:44 Go to previous messageGo to next message
Uri Shani is currently offline Uri ShaniFriend
Messages: 18
Registered: July 2009
Junior Member
Many thanks.
I looked at Snippet135 and made out of it something simpler which only shows the Shell, but not the label inside - what is missing there?

package tests;

/*******************************************************************************
/*
 * example snippet: embed Swing/AWT in SWT
 *
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 * 
 * @since 3.0
 */
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class BridgeSnippet {

	public static void main(String[] args) {
		final Display display = new Display();
		final Shell shell = new Shell(display);
		shell.setText("SWT and Swing/AWT Example");
		Composite composit = new Composite(shell, SWT.EMBEDDED);
		java.awt.Frame frame = SWT_AWT.new_Frame(composit);
		frame.setTitle("AWT Frame");
		java.awt.Label label = new java.awt.Label("Hello world");
		frame.add(label);
		
		composit.setVisible(true);
		shell.open();
		while(!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep();
		}
		display.dispose();
	}
}
Re: Running Swing or AWT widgets within SWT. [message #531104 is a reply to message #531074] Mon, 03 May 2010 17:24 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Uri Shani wrote:
> Many thanks.
> I looked at Snippet135 and made out of it something simpler which only
> shows the Shell, but not the label inside - what is missing there?

You need to set layouts on your shell and composite. Even a FillLayout
will display the label.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Running Swing or AWT widgets within SWT. [message #531133 is a reply to message #531104] Mon, 03 May 2010 20:05 Go to previous message
Uri Shani is currently offline Uri ShaniFriend
Messages: 18
Registered: July 2009
Junior Member
Many, many thanks... working now.
- Uri Razz
Previous Topic:AutoSizing the Tree Columns
Next Topic:Is it possible to use combo with cascade behavior ?
Goto Forum:
  


Current Time: Thu Apr 18 16:55:40 GMT 2024

Powered by FUDForum. Page generated in 0.02401 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top