Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » silly newbie question
silly newbie question [message #444148] Thu, 07 October 2004 18:42 Go to next message
Vincent Jenks is currently offline Vincent JenksFriend
Messages: 27
Registered: July 2009
Junior Member
How do I simply launch one SWT shell window from another? I know how to
add the event to a button or another type of widget but how do I call
another window?
Re: silly newbie question [message #444190 is a reply to message #444148] Fri, 08 October 2004 11:49 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dominique.vlieghe.dmbr.ugent.be

See

http://www.cs.umanitoba.ca/~eclipse/

Tutorial 2, page 1

Hope this helps

Vincent Jenks wrote:
> How do I simply launch one SWT shell window from another? I know how to
> add the event to a button or another type of widget but how do I call
> another window?
>
Re: silly newbie question [message #444238 is a reply to message #444190] Sun, 10 October 2004 02:34 Go to previous messageGo to next message
Vincent Jenks is currently offline Vincent JenksFriend
Messages: 27
Registered: July 2009
Junior Member
Dominique Vlieghe wrote:

> See

> http://www.cs.umanitoba.ca/~eclipse/

> Tutorial 2, page 1

> Hope this helps

> Vincent Jenks wrote:
> > How do I simply launch one SWT shell window from another? I know how to
> > add the event to a button or another type of widget but how do I call
> > another window?
> >

Actually no, that doesn't explain it at all. That's a very vague
brushing-over of how it can be done but the code that was generated by the
Visual Editor isn't the same, it's done in VE using the open() method of
the shell rather than adding the display to the shell's constructor, which
would appear to limit my flexibility.

For example...

public static void main(String[] args)
{
Display display = Display.getDefault();
SnapMain thisClass = new SnapMain();
thisClass.createSShell();
thisClass.snapMainShell.open();

while (!thisClass.snapMainShell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}

display.dispose();
}

...createSShell() looks like this:

public void createSShell()
{
snapMainShell = new Shell();
button = new Button(snapMainShell, SWT.NONE);
snapMainShell.setSize(new org.eclipse.swt.graphics.Point(726, 538));
snapMainShell.setText("Snap Trials - Alpha Demo 0.1");
button.setBounds(new org.eclipse.swt.graphics.Rectangle(572, 10, 75,
24));
button.setText("Options");
button.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter()
{
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e)
{
System.out.println("widgetSelected()");
launchOptionsMenu(); //!!
}
});
}

When I attempt to do it like this, calling another shell from within the
main window (widgetSelected event of a button, see above), the application
crashes:

private void launchOptionsMenu()
{
Display display = Display.getDefault();
OptionsMenu op = new OptionsMenu();
optionsShell = op.getSShell();

optionsShell.open();
optionsShell.dispose();

while (!optionsShell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}

display.dispose();
}

Can someone perhaps provide some URLs that may have actual code-examples
rather than one-liner explanations on how it's generally done?

I'm having a real hard time w/ this...and it's such a simple concept.

Thanks!
Re: silly newbie question [message #444240 is a reply to message #444190] Sun, 10 October 2004 04:20 Go to previous message
Vincent Jenks is currently offline Vincent JenksFriend
Messages: 27
Registered: July 2009
Junior Member
Dominique Vlieghe wrote:

> See

> http://www.cs.umanitoba.ca/~eclipse/

> Tutorial 2, page 1

> Hope this helps

> Vincent Jenks wrote:
> > How do I simply launch one SWT shell window from another? I know how to
> > add the event to a button or another type of widget but how do I call
> > another window?
> >

I seem to have "rigged up" a way to do it but I'm entirely unsure if this
is correct or a proper way to approach this. I guess my question is; Is
there an easier way AND am I properly disposing of everything that I
should doing it this way:

function that lanuches window, called from widgetSelected event later on
(SnapMain.class):
private void launchOptionsMenu()
{
Display display = Display.getDefault();
OptionsMenu op = new OptionsMenu();
op.run(display);
}

run() method (used to be main(String[] args)) in OptionsMenu.class:
public void run(Display display)
{
OptionsMenu thisClass = new OptionsMenu();
thisClass.createSShell();
thisClass.sShell.open();
}

It runs, it works, and that's great...however...there may be a better,
more efficient way?

Thanks!!
Previous Topic:No suitable Log constructor ???
Next Topic:Grid component
Goto Forum:
  


Current Time: Fri Mar 29 02:14:10 GMT 2024

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

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

Back to the top