Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT widget not displayed
SWT widget not displayed [message #502848] Wed, 09 December 2009 17:44 Go to next message
No real name is currently offline No real name
Messages: 6
Registered: December 2009
Junior Member
Hi,
I am writing an Eclipse plug-in which launches an SWT widget. Here's what I'm writing:

public void run(IAction action) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Button Example");
shell.setBounds(100, 100, 200, 100);
shell.setLayout(new FillLayout());
final Button button = new Button(shell, SWT.PUSH);
button.setText("Click Me Now");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
button.setText("I Was Clicked");
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();

}

Although the window is displayed ok when placed in the main method of a java application, over here it isn't working. Can anyone help me please?

Thanks and regards,
Kurt
Re: SWT widget not displayed [message #502877 is a reply to message #502848] Thu, 10 December 2009 02:54 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel Krügler
Messages: 853
Registered: July 2009
Senior Member
kurtanatlus@gmail.com wrote:
> Hi, I am writing an Eclipse plug-in which launches an SWT widget. Here's
> what I'm writing:
>
> public void run(IAction action) {
> Display display = new Display();
> Shell shell = new Shell(display);
> shell.setText("Button Example");
> shell.setBounds(100, 100, 200, 100);
> shell.setLayout(new FillLayout());
> final Button button = new Button(shell, SWT.PUSH);
> button.setText("Click Me Now");
> button.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent event) {
> button.setText("I Was Clicked");
> }
> });
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) display.sleep();
> }
> display.dispose();
> }
>
> Although the window is displayed ok when placed in the main method of a
> java application, over here it isn't working. Can anyone help me please?

Your question isn't very helpful - please define "it isn't working".

In case of an error, we need to know more than this. It might probably
also be useful to describe which platform/OS you are using.

I don't mean it as an offense, but I really recommend to obey the basic
rules of questions in the internet:

http://catb.org/~esr/faqs/smart-questions.html

- Daniel Krügler
Re: SWT widget not displayed [message #502880 is a reply to message #502877] Thu, 10 December 2009 03:00 Go to previous messageGo to next message
No real name is currently offline No real name
Messages: 6
Registered: December 2009
Junior Member
Hi, yes good point. By 'not working', I meant the window not being displayed.

I solved the problem some time ago.
I replaced the line
Display display = new Display();
with this
Display display = PlatformUI.createDisplay();

Thanks and regards,
Kurt
Re: SWT widget not displayed [message #502882 is a reply to message #502880] Thu, 10 December 2009 03:02 Go to previous message
No real name is currently offline No real name
Messages: 6
Registered: December 2009
Junior Member
Bdw, with regards to OS, I'm running Windows XP SP3 and Eclipse 3.5 Galileo

Regards,
Kurt
Previous Topic:SWT table filtering
Next Topic:Tree.setTopItem fails?
Goto Forum:
  


Current Time: Wed Aug 20 05:01:48 EDT 2014

Powered by FUDForum. Page generated in 0.02425 seconds