HelloWorld standalone: No text on Buttons or Labels [message #464420] |
Wed, 23 November 2005 06:39  |
Eclipse User |
|
|
|
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();
);
}
while (!shell.isDisposed())
{ if (!display.readAndDispatch())
{ display.sleep();
}
}
display.dispose();
}
}
..............
I get no error message to the console, the 'swt-win32-3138.dll' is on
java.library.path.
What can I do?
How could/should I approach this kind of problem?
I have experimented with java.library.path ja java.class.path without
any difference so far.
It's so surprising that the same code functions in different ways as
standalone or inside of Eclipse - without any obvious reason.
Risto
|
|
|
|
|
Re: HelloWorld standalone: No text on Buttons or Labels [message #464498 is a reply to message #464420] |
Wed, 23 November 2005 09:38   |
Eclipse User |
|
|
|
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.04315 seconds