Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » how to open another window by pushing a button in a window?
how to open another window by pushing a button in a window? [message #442218] Mon, 30 August 2004 01:01 Go to next message
Eclipse UserFriend
Originally posted by: gplai.yahoo.com

Hi,

This sounds simple but I can't make it worked.

I already developed two forms with SWT widgets and have them passed tests.
One window should be opened by pushing a command button in another window. I
used widgetSelected event to capture the push action and saw it fired
successfully. But the sub-window just didn't appear at all.

I think this should be easy but just can't figure out the relationship
between parent shell and child shell. Hope someone can kindly show me the
way to it.

Thanks,

Robert Li
Re: how to open another window by pushing a button in a window? [message #442221 is a reply to message #442218] Mon, 30 August 2004 04:02 Go to previous messageGo to next message
user is currently offline userFriend
Messages: 296
Registered: July 2009
Senior Member
bob lai wrote:
> Hi,
>
> This sounds simple but I can't make it worked.
>
> I already developed two forms with SWT widgets and have them passed tests.
> One window should be opened by pushing a command button in another window. I
> used widgetSelected event to capture the push action and saw it fired
> successfully. But the sub-window just didn't appear at all.
>
> I think this should be easy but just can't figure out the relationship
> between parent shell and child shell. Hope someone can kindly show me the
> way to it.
>
> Thanks,
>
> Robert Li
>
>
check the following, they work for me.

norwood sisson


From: christophe_cornu@ca.ibm.com (Christophe Cornu)
Newsgroups: eclipse.platform.swt
Subject: Re: IE Browser and dispose

Hi Kolloc,

The following snippet brings up a shell with a button. Clicking on the
button creates a second shell with a browser widget. Clicking more times
brings the existing second shell to the top of the screen.

Maybe your past code was running the event loop from a Shell you are
disposing. The snippet below runs the event loop from the main application
Shell - the one that is disposed only when the entire application
terminates.

When the user closes the second shell, the second shell disposes all its
children including the browser widget. Let us know if this does not answer
your question.

Chris

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.browser.*;

public class PRBrowser {

static Shell dialog = null;
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Main Shell");
shell.setLayout(new FillLayout());
Button b = new Button(shell, SWT.PUSH);
b.setText("Show the Dialog");
b.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
if (dialog == null || dialog.isDisposed()) {
dialog = new Shell(display);
dialog.setLayout(new FillLayout());
Browser browser = new Browser(dialog, SWT.NONE);
browser.setUrl("http://www.eclipse.org");
dialog.open();
} else {
dialog.forceActive();
}
}
});
shell.open();

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


From: "Veronika Irvine" <veronika_irvine@oti.com>
Newsgroups: eclipse.platform.swt
Subject: Re: multiple top-level shells


The problem you could run into is that display is disposed causing
display.getShells() to throw an exception.

The following is better:

while (!display.isDisposed() && display.getShells().length > 0) {
if (!display.readAndDispatch ()) {
display.sleep ();
}
}
Re: how to open another window by pushing a button in a window? [message #442231 is a reply to message #442218] Mon, 30 August 2004 15:08 Go to previous message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
See:
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet50.java?rev=HEAD&a mp;content-type=text/vnd.viewcvs-markup

and

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet63.java?rev=HEAD&a mp;content-type=text/vnd.viewcvs-markup

"bob lai" <gplai@yahoo.com> wrote in message news:cgttvp$na$1@eclipse.org...
> Hi,
>
> This sounds simple but I can't make it worked.
>
> I already developed two forms with SWT widgets and have them passed tests.
> One window should be opened by pushing a command button in another window.
I
> used widgetSelected event to capture the push action and saw it fired
> successfully. But the sub-window just didn't appear at all.
>
> I think this should be easy but just can't figure out the relationship
> between parent shell and child shell. Hope someone can kindly show me the
> way to it.
>
> Thanks,
>
> Robert Li
>
>
Previous Topic:Widgets overlapping instead of shrinking
Next Topic:Working with the "About dialog" of RCP
Goto Forum:
  


Current Time: Fri Apr 26 04:20:30 GMT 2024

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

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

Back to the top