WindowEvent is sent by a Browser when
a new window needs to be created or when an existing window needs to be
closed. This notification occurs when a javascript command such as
window.open or window.close gets executed by
a Browser.
The following example shows how WindowEvent's are typically
handled.
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Main Window");
shell.setLayout(new FillLayout());
Browser browser = new Browser(shell, SWT.NONE);
initialize(display, browser);
shell.open();
browser.setUrl("http://www.eclipse.org");
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
static void initialize(final Display display, Browser browser) {
browser.addOpenWindowListener(new OpenWindowListener() {
public void open(WindowEvent event) {
// Certain platforms can provide a default full browser.
// simply return in that case if the application prefers
// the default full browser to the embedded one set below.
if (!event.required) return;
// Embed the new window
Shell shell = new Shell(display);
shell.setText("New Window");
shell.setLayout(new FillLayout());
Browser browser = new Browser(shell, SWT.NONE);
initialize(display, browser);
event.browser = browser;
}
});
browser.addVisibilityWindowListener(new VisibilityWindowListener() {
public void hide(WindowEvent event) {
Browser browser = (Browser)event.widget;
Shell shell = browser.getShell();
shell.setVisible(false);
}
public void show(WindowEvent event) {
Browser browser = (Browser)event.widget;
Shell shell = browser.getShell();
if (event.location != null) shell.setLocation(event.location);
if (event.size != null) {
Point size = event.size;
shell.setSize(shell.computeSize(size.x, size.y));
}
if (event.addressBar || event.menuBar || event.statusBar || event.toolBar) {
// Create widgets for the address bar, menu bar, status bar and/or tool bar
// leave enough space in the Shell to accommodate a Browser of the size
// given by event.size
}
shell.open();
}
});
browser.addCloseWindowListener(new CloseWindowListener() {
public void close(WindowEvent event) {
Browser browser = (Browser)event.widget;
Shell shell = browser.getShell();
shell.close();
}
});
}
The following notifications are emitted when the user selects a hyperlink that targets a new window
or as the result of a javascript that executes window.open.
Main Browser
Second Browser
CloseWindowListener, OpenWindowListener, VisibilityWindowListener, Sample code and further information
| Modifier and Type | Field and Description |
|---|---|
| public boolean | addressBar
Specifies whether the |
| public Browser | browser
|
| public Point | location
Requested location for the |
| public boolean | menuBar
Specifies whether the |
| public boolean | required
Specifies whether the platform requires the user to provide a
|
| pack-priv static final long | |
| public Point | size
Requested |
| public boolean | statusBar
Specifies whether the |
| public boolean | toolBar
Specifies whether the |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public String | Returns: a string representation of the eventOverrides org. |
| addressBar | back to summary |
|---|---|
| public boolean addressBar Specifies whether the
| |
| browser | back to summary |
|---|---|
| public Browser browser
| |
| location | back to summary |
|---|---|
| public Point location Requested location for the | |
| menuBar | back to summary |
|---|---|
| public boolean menuBar Specifies whether the
| |
| required | back to summary |
|---|---|
| public boolean required Specifies whether the platform requires the user to provide a
| |
| serialVersionUID | back to summary |
|---|---|
| pack-priv static final long serialVersionUID | |
| size | back to summary |
|---|---|
| public Point size Requested | |
| statusBar | back to summary |
|---|---|
| public boolean statusBar Specifies whether the
| |
| toolBar | back to summary |
|---|---|
| public boolean toolBar Specifies whether the
| |
| WindowEvent | back to summary |
|---|---|
| public WindowEvent(Widget widget) Constructs a new instance of this class.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides org. Returns a string containing a concise, human-readable description of the receiver. | |