添加OpenWindowListener : 浏览器 « SWT « Java 教程

En
Java 教程
1. 语言基础
2. 数据类型
3. 操作符
4. 流程控制
5. 类定义
6. 开发相关
7. 反射
8. 正则表达式
9. 集合
10. 线
11. 文件
12. 泛型
13. 本土化
14. Swing
15. Swing事件
16. 二维图形
17. SWT
18. SWT 二维图形
19. 网络
20. 数据库
21. Hibernate
22. JPA
23. JSP
24. JSTL
25. Servlet
26. Web服务SOA
27. EJB3
28. Spring
29. PDF
30. 电子邮件
31. 基于J2ME
32. J2EE应用
33. XML
34. 设计模式
35. 日志
36. 安全
37. Apache工具
38. 蚂蚁编译
39. JUnit单元测试
Java
Java 教程 » SWT » 浏览器 
17. 86. 9. 添加OpenWindowListener

Browser conventions allow spawning new browser windows. Things that can trigger a new browser window include the following:

  1. The user right-clicks a link and selects Open in New Window from the context menu (note that you must build this functionality yourself).
  2. The user holds down Shift while clicking a link.
  3. The user clicks a link that has a named target for which no browser currently exists.

When the user performs an action within the browser that spawns a new browser window, any OpenWindowListeners are first notified. OpenWindowListener declares one method:

public void open(WindowEvent event)

As with CloseWindowListener, the three WindowEvent fields (browser, location, and field) are null when passed to open(), and the widget field inherited from TypedEvent contains a reference to the current browser.

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.OpenWindowListener;
import org.eclipse.swt.browser.WindowEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class OpenWindowListenerUsing {
  public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);

    Browser browser = new Browser(shell, SWT.NONE);
    browser.setBounds(55600600);

    browser.addOpenWindowListener(new OpenWindowListener() {
      public void open(WindowEvent event) {
        Shell shell = new Shell(display);
        shell.setText("New Window");
        shell.setLayout(new FillLayout());
        Browser browser = new Browser(shell, SWT.NONE);
        event.browser = browser;
      }
    });

    browser.setUrl("http://java2s.com");
    shell.open();

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
  }
}
17. 86. 浏览器
17. 86. 1. 使用浏览器加载网页使用浏览器加载网页
17. 86. 2. 浏览器支持以下事件
17. 86. 3. 添加StatusTextListener到浏览器添加StatusTextListener到浏览器
17. 86. 4. 添加ProgressListener到浏览器添加ProgressListener到浏览器
17. 86. 5. 使用进度条,以显示浏览器的进展使用进度条,以显示浏览器的进展
17. 86. 6. 添加LocationListener到浏览器
17. 86. 7. 添加CloseWindowListener到浏览器
17. 86. 8. 添加VisibilityWindowListener
17. 86. 9. 添加OpenWindowListener
17. 86. 10. 添加TitleListener到浏览器
17. 86. 11. 浏览器:打开浏览器(弹出式窗口拦截器)
17. 86. 12. 渲染内存中的HTML
17. 86. 13. Browser: render HTML that includes relative links from memoryBrowser: render HTML that includes relative links from memory
17. 86. 14. 浏览器:修改DOM(执行JavaScript )浏览器:修改DOM(执行JavaScript )
17. 86. 15. 浏览器:查询DOM节点值浏览器:查询DOM节点值
17. 86. 16. 高级浏览器高级浏览器
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.