FormToolkit working in a standalone SWT/Jface app? [message #467239] |
Thu, 26 January 2006 21:16 |
Eclipse User |
|
|
|
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 #467334 is a reply to message #467332] |
Sun, 29 January 2006 09:27 |
Sanjay Chaudhuri 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
{
public static void main(String[] args)
{
Display display = new Display();
Shell shell = new Shell( display );
shell.setLayout( new GridLayout( 1, false));
ScrolledComposite scrlComposite = new ScrolledComposite( shell, SWT.H_SCROLL | SWT.V_SCROLL);
GridLayout gridScrlComposite = new GridLayout( 1, false);
scrlComposite.setLayout( gridScrlComposite);
scrlComposite.setLayoutData( new GridData( GridData.FILL_BOTH));
Composite composite = new Composite( scrlComposite, SWT.NONE);
scrlComposite.setContent( composite);
GridLayout gridComposite = new GridLayout( 1, false);
composite.setLayout( gridComposite);
composite.setLayoutData( new GridData( GridData.FILL_BOTH));
FormToolkit formToolkit = new FormToolkit( display);
formToolkit.paintBordersFor( composite);
Text txtField = formToolkit.createText( composite, "", SWT.NONE );
Point p = composite.computeSize( SWT.DEFAULT, SWT.DEFAULT, true );
scrlComposite.setMinWidth( p.x );
scrlComposite.setMinHeight( p.y );
scrlComposite.setExpandHorizontal( true );
scrlComposite.setExpandVertical( true );
shell.pack();
shell.open();
while ( !shell.isDisposed() )
{
if ( !display.readAndDispatch() )
display.sleep();
}
display.dispose();
}
}
</code>
|
|
|
Powered by
FUDForum. Page generated in 0.02236 seconds