Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » FormToolkit working in a standalone SWT/Jface app?
FormToolkit working in a standalone SWT/Jface app? [message #467239] Thu, 26 January 2006 21:16 Go to next message
Eclipse UserFriend
Originally posted by: andre.dietisheim.gmail.com

I tried to use the FormToolkit in a swt/jface app, because I didn't see any reason that it shoudn't work outside of the eclipse platform. I couldn't have it render any single widget. Does the formToolkit run on in ViewParts?
Re: FormToolkit working in a standalone SWT/Jface app? [message #467332 is a reply to message #467239] Sun, 29 January 2006 08:41 Go to previous messageGo to next message
Sanjay Chaudhuri is currently offline Sanjay ChaudhuriFriend
Messages: 19
Registered: July 2009
Junior Member
No, you can run it standalone. There is nothing special that needs to be done. Just ensure that, you have the composite and the layouts properly in place, else you will not see anything. Infact this goes with any control. To get started, it is better to use fill layout, I guess, and then use, ScrolledComposite with GridLayout.

Sanjay
Re: FormToolkit working in a standalone SWT/Jface app? [message #467334 is a reply to message #467332] Sun, 29 January 2006 09:27 Go to previous message
Sanjay Chaudhuri is currently offline Sanjay ChaudhuriFriend
Messages: 19
Registered: July 2009
Junior Member
Well, here is a code snippet to create a TEXT-BOX with <B>ScrolledComposite</B> and a <B>GridLayout</B>.
Few things to note, else you will not see anything:
- Shell <B>must</B> have a layout
- While using a <I>ScrolledComposite</I>, <code>setLayoutData(...), setMinWidth(...), setMinHeight(...), setExpandHorizontal(...) and setExpandVertical(...)</code> <B>must</B> be used.

<code>
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.FormToolkit;

public class FormToolkitExample
{
&nbsp;public static void main(String[] args)
&nbsp;{
&nbsp; &nbsp;Display display = new Display();
&nbsp; &nbsp;Shell shell = new Shell( display );
&nbsp; &nbsp;shell.setLayout( new GridLayout( 1, false));

&nbsp; &nbsp;ScrolledComposite scrlComposite = new ScrolledComposite( shell, SWT.H_SCROLL | SWT.V_SCROLL);
&nbsp; &nbsp;GridLayout gridScrlComposite = new GridLayout( 1, false);
&nbsp; &nbsp;scrlComposite.setLayout( gridScrlComposite);
&nbsp; &nbsp;scrlComposite.setLayoutData( new GridData( GridData.FILL_BOTH));

&nbsp; &nbsp;Composite composite = new Composite( scrlComposite, SWT.NONE);
&nbsp; &nbsp;scrlComposite.setContent( composite);
&nbsp; &nbsp;GridLayout gridComposite = new GridLayout( 1, false);
&nbsp; &nbsp;composite.setLayout( gridComposite);
&nbsp; &nbsp;composite.setLayoutData( new GridData( GridData.FILL_BOTH));

&nbsp; &nbsp;FormToolkit formToolkit = new FormToolkit( display);
&nbsp; &nbsp;formToolkit.paintBordersFor( composite);

&nbsp; &nbsp;Text txtField = formToolkit.createText( composite, "", SWT.NONE );

&nbsp; &nbsp;Point p = composite.computeSize( SWT.DEFAULT, SWT.DEFAULT, true );
&nbsp; &nbsp;scrlComposite.setMinWidth( p.x );
&nbsp; &nbsp;scrlComposite.setMinHeight( p.y );

&nbsp; &nbsp;scrlComposite.setExpandHorizontal( true );
&nbsp; &nbsp;scrlComposite.setExpandVertical( true );

&nbsp; &nbsp;shell.pack();
&nbsp; &nbsp;shell.open();

&nbsp; &nbsp;while ( !shell.isDisposed() )
&nbsp; &nbsp;{
&nbsp; &nbsp; &nbsp;if ( !display.readAndDispatch() )
&nbsp; &nbsp; &nbsp; &nbsp;display.sleep();
&nbsp; &nbsp;}
&nbsp; &nbsp;display.dispose();
&nbsp;}
}
</code>
Previous Topic:HELP with HTML in SWT?
Next Topic:Need help with JFace Wizard
Goto Forum:
  


Current Time: Thu Apr 18 08:27:42 GMT 2024

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

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

Back to the top