Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-07-2008, 05:44 PM
Java Tip's Avatar
Moderator
 
Join Date: Nov 2007
Posts: 1,691
Rep Power: 5
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Default How to modify HTML title tag
Code:
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.browser.ProgressListener;
import org.eclipse.swt.browser.TitleEvent;
import org.eclipse.swt.browser.TitleListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class Snippet159 {
  public static void main(String[] args) {
    final String newTitle = "New Value for Title";
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    final Browser browser = new Browser(shell, SWT.NONE);
    browser.addTitleListener(new TitleListener() {
      public void changed(TitleEvent event) {
        System.out.println("TitleEvent: " + event.title);
        shell.setText(event.title);
      }
    });
    browser.addProgressListener(new ProgressListener() {
      public void changed(ProgressEvent event) {
      }

      public void completed(ProgressEvent event) {
        /*
         * Set HTML title tag using JavaScript and DOM when page has
         * been loaded
         */
        boolean result = browser.execute("document.title='" + newTitle
            + "'");
        if (!result) {
          /*
           * Script may fail or may not be supported on certain
           * platforms.
           */
          System.out.println("Script was not executed.");
        }
      }
    });
    /* Load an HTML document */
    browser.setUrl("http://www.eclipse.org");
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
  }
}
__________________
"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I modify a specific component within a active internalframe? LearningJavaASAP AWT / Swing 1 04-24-2008 07:35 PM
Modify A* Algorithm prakharbirla Advanced Java 1 02-13-2008 07:25 PM
Modify/create AVI's INFO BLOCK Agus211 New To Java 0 02-11-2008 04:20 PM
Hiding the frame’s title bar Java Tip Java Tips 0 12-21-2007 09:41 AM
How can I add an ICON on a JDialog's Title-Bar? iimasd AWT / Swing 2 11-06-2007 01:54 PM


All times are GMT +2. The time now is 12:20 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org