|
|
|
Re: HelloWorld standalone: No text on Buttons or Labels [message #464498 is a reply to message #464420] |
Wed, 23 November 2005 14:38 |
Stefan Langer Messages: 236 Registered: July 2009 |
Senior Member |
|
|
Looking at your code it is totaly wrong. There is an error at the marked
line. I'm guessing Eclipse is being tolerant and runs it because of that
but standalone isnt't. Try the code at the end of mail instead.
Regards
Stefan
Risto Luukkanen wrote:
> My problem is pretty basic:
>
> When I run HelloWorld inside of Eclipse - no problem. But when run it as
> standalone: The window opens as it should, but no text comes visible!
> The source code is like this:
> .........
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Label;
> import org.eclipse.swt.SWT;
>
> public class HelloWorld
> {
> public static void main(String[] args)
> { Display display = new Display();
> Shell shell = new Shell(display);
> Label label = new Label(shell, SWT.CENTER);
> label.setBounds(50,50,75,40);
> label.setText("Hello, World");
> shell.open();
> );
HERE IS AN ERROR
> }
>
> while (!shell.isDisposed())
> { if (!display.readAndDispatch())
> { display.sleep();
> }
> }
> display.dispose();
> }
> }
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class HelloWorld
{
/**
* @param args
*/
public static void main(String[] args)
{
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout()); // <- set a layout
Label label = new Label(shell, SWT.CENTER);
//label.setBounds(50,50,75,40); <- don't need this when you set a layout
label.setText("Hello, World");
shell.pack(); // make shell compact
shell.open();
while (!shell.isDisposed())
{
if(!display.readAndDispatch())
{
display.sleep();
}
}
display.dispose();
}
}
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03586 seconds