aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes lame n00b question... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "lame n00b question..." Watch "lame n00b question..." New topic
Author

lame n00b question...

Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
I'm new to SWT so I'm just trying to figure out how I can launch one window from another?

For example, I have a "Main" window that I'd like a button on that when pressed (widgetSelected), a second "Options" window launches and is set as modal.

How can I send values from the "Main" form to the "Options" form as well?

I'm coming from the .NET world where you simple instantiate the class and call the a void to launch the window.

I understand SWT events, that's not the issue, I need to know *what* to put inside of the event that launches a sub-window.

Thanks!
Barry Andrews
Ranch Hand

Joined: Sep 05, 2000
Posts: 523

So I assume your Options window is going to be a Dialog. So just subclass org.eclipse.swt.widgets.Dialog You can create an open() method that creates all your widgets on the Dialog, and make sure to pass the SWT.APPLICATION_MODAL style bit to the Dialog's Shell so that your window will be modal. Create a new instance of your Dialog in the widgetSelected() method and call your open() method. Bingo!

Post back if this does not clarify things.
Barry Andrews
Ranch Hand

Joined: Sep 05, 2000
Posts: 523

P.S. Don't start a topic with "lame noob question" There are no lame questions, most of the time.

Sometimes people give lame answers though.
Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
Well, I think I follow you...anyhow here's what I did and the application crashes when I trigger the event on the button that is supposed to launch the "Dialog" or window, or what have you...

For example, the main function in SnapMain.class...



...createSShell() looks like this:



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



The error is:



Interstingly, if I fire the OptionsWindow createSShell method first, the program doesn't exactly crash, it just vanishes, and if I run it within eclipse - I don't get an error message.

I'm obviously way off here...just need a clue!

No more lame n00bie questions, I promise...from now on I'll ignore the fact that it is in fact a lame question!

Thanks!
Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
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):



run() method (used to be main(String[] args)) in OptionsMenu.class:



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

Thanks!!
Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
Originally posted by Barry Andrews:
So I assume your Options window is going to be a Dialog. So just subclass org.eclipse.swt.widgets.Dialog You can create an open() method that creates all your widgets on the Dialog, and make sure to pass the SWT.APPLICATION_MODAL style bit to the Dialog's Shell so that your window will be modal. Create a new instance of your Dialog in the widgetSelected() method and call your open() method. Bingo!

Post back if this does not clarify things.


I've found several ways to launch windows from other windows but I'm very interested in getting what you describe above to work.

I tried it, I can't get anywhere w/ it, could you perhaps provide tiny code sample?

I inherted the Dialog class, provided the superclass its parameters but am unable to get it to function propertly, it doesn't launch at all.

Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: lame n00b question...