Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » HelloWorld standalone: No text on Buttons or Labels
HelloWorld standalone: No text on Buttons or Labels [message #464420] Wed, 23 November 2005 11:39 Go to next message
Risto Luukkanen is currently offline Risto LuukkanenFriend
Messages: 13
Registered: July 2009
Junior Member
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 #464422 is a reply to message #464420] Wed, 23 November 2005 12:53 Go to previous messageGo to next message
Stefan Langer is currently offline Stefan LangerFriend
Messages: 236
Registered: July 2009
Senior Member
You should put a layout on the shell!

shell.setLayout(new FillLayout()) or the like.

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();
> );
> }
>
> 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 #464497 is a reply to message #464422] Wed, 23 November 2005 14:26 Go to previous messageGo to next message
Risto Luukkanen is currently offline Risto LuukkanenFriend
Messages: 13
Registered: July 2009
Junior Member
Thanks for the advice Stefan!

I added the layout as you suggested, but it made no difference! No 'Hello' -text comes visible as standalone, but then 'HelloWorld' does come to the screen when I run the class inside of Eclipse.

Risto
Re: HelloWorld standalone: No text on Buttons or Labels [message #464498 is a reply to message #464420] Wed, 23 November 2005 14:38 Go to previous messageGo to next message
Stefan Langer is currently offline Stefan LangerFriend
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();
}
}
Re: HelloWorld standalone: No text on Buttons or Labels [message #464540 is a reply to message #464498] Thu, 24 November 2005 08:41 Go to previous messageGo to next message
Risto Luukkanen is currently offline Risto LuukkanenFriend
Messages: 13
Registered: July 2009
Junior Member
I think I got this solved: In Windows I have to run my standalone application with <i>javaw</i> -command, not with <i>java</i> !

However, sometimes I do get the Label- and Button texts visible also by using <i>java</i> and in some cases Label.setText() leaves the text 'unvisible' without throwing an exception. What makes this difference remains mystery to me.

Risto

In fact, I have to admit, I didn't quote my code completely, therefore it seemed to be totally wrong. Thanks Stefan!
Re: HelloWorld standalone: No text on Buttons or Labels [message #464542 is a reply to message #464540] Thu, 24 November 2005 09:01 Go to previous messageGo to next message
Stefan Langer is currently offline Stefan LangerFriend
Messages: 236
Registered: July 2009
Senior Member
I run on windows and don't seem to have this problem... strange.
I guessed that there was some quoting mistake but I just wanted to make
sure that you have a running program. :)

Regards
Stefan

Risto Luukkanen wrote:
> I think I got this solved: In Windows I have to run my standalone application with <i>javaw</i> -command, not with <i>java</i> !
>
> However, sometimes I do get the Label- and Button texts visible also by using <i>java</i> and in some cases Label.setText() leaves the text 'unvisible' without throwing an exception. What makes this difference remains mystery to me.
>
> Risto
>
> In fact, I have to admit, I didn't quote my code completely, therefore it seemed to be totally wrong. Thanks Stefan!
Re: HelloWorld standalone: No text on Buttons or Labels [message #464545 is a reply to message #464542] Thu, 24 November 2005 09:48 Go to previous message
Risto Luukkanen is currently offline Risto LuukkanenFriend
Messages: 13
Registered: July 2009
Junior Member
It was so confusing, I tried this in six pcs and in three 'java' failed
to bring the Labeltext visible while in three others the text came as it
should.

I have two swt/jface books and they make no mention of 'java vs javaw',
which also seems strange.

Risto
Previous Topic:Problems with syncExec on Windows Mobile 2005
Next Topic:non-rectangular window -switching
Goto Forum:
  


Current Time: Mon Dec 22 20:56:16 GMT 2014

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

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