🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #10964

Re: JEditorPane: Hyperlinks inside of HTML-Document

#10964
From: antenangeli1962
Date: Thu, 22 Jul 1999 00:00
109 lines
3710 bytes
In article <37750024.BC29C69@uib.de>,
  detlef oertel <oertel@uib.de> wrote:
> Hello,
>
> I want to use JEditorPane to display a online Helpfile.
> With
>
> void jEditorPane1_hyperlinkUpdate(HyperlinkEvent e)
>  {
>   JEditorPane pane = (JEditorPane) e.getSource();
>    try
>     {
>       pane.setPage(e.getURL());
>     }
>     catch (Throwable t)
>     {
>      t.printStackTrace();
>     }
>  }
>
> i am able to load other HTML-Files. But if the URL points to a
position
> inside of the document (for Example "#3.Header") it only reloads the
> document and shows it from the top.
>
> Can anybody tell me what I have missed ?
>
> thanks a lot.
>
> detlef oertel
> oertel@uib.de


Maybe this will help you, it works for me with the Sun Java compiler:

public class HTMLDisplayer extends    JPanel
                           implements HyperlinkListener
{
   /**
    * Pane where the HTML document will be displayed
    */
   JEditorPane d_HTMLEditor;


   /**
    * Given the URL to the document, display it.
    *
    * @param url The url where the document is
    */
   public HTMLDisplayer ( URL url )
   {
      super ( new BorderLayout () );
      initialize ( url );
   }

   /**
    * Do the actual initialization
    *
    * @param url URL with the document to be displayed
    */
   private void initialize ( URL url )
   {
      try {
         d_HTMLEditor = new JEditorPane ( url );
      } catch ( IOException e ) {
         JOptionPane.showMessageDialog ( this,
                                         "File read error!",
                                         "Open",
                                         JOptionPane.ERROR_MESSAGE );
      }
      d_HTMLEditor.setEditable ( false );
      d_HTMLEditor.addHyperlinkListener ( this );
      JScrollPane scroller = new JScrollPane ( d_HTMLEditor );
      scroller.setBorder ( new BevelBorder ( BevelBorder.LOWERED ) );
      add ( scroller, BorderLayout.CENTER );
   }

   /**
    * Notification of a change relative to a hyperlink.
    */
   public void hyperlinkUpdate(HyperlinkEvent e)
   {
      if ( e.getEventType() == HyperlinkEvent.EventType.ACTIVATED )
         try {
            d_HTMLEditor.setPage ( e.getURL () );
         } catch ( IOException x ) {
            JOptionPane.showMessageDialog ( this,
                                            "File read error!",
                                            "Open",
                                            JOptionPane.ERROR_MESSAGE );
         }
   }

}

However, this has a problem following hyperlinks in the same document.
Apparently you need to include the document name as part of the HREF
link, otherwise the call to setPage ( e.getURL () ) won't work. In
other words, in your HTML source you need to:

<A HREF="filename.html#refname">The link</A>

Hope that helps.

Alberto


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
Technical Details
Message-ID: <7n7oa9$28s$1@nnrp1.deja.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <37750024.BC29C69@uib.de>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,441d9d1e348f9542
X-Google-Attributes: gid111d45,public
From: antenangeli1962@my-deja.com
Subject: Re: JEditorPane: Hyperlinks inside of HTML-Document
Date: 1999/07/22
Message-ID: <7n7oa9$28s$1@nnrp1.deja.com>
X-Deja-AN: 504075706
References: <37750024.BC29C69@uib.de>
X-Http-Proxy: 1.1 x32.deja.com:80 (Squid/1.1.22) for client 209.99.32.41
Organization: Deja.com - Share what you know. Learn what you don't.
X-Article-Creation-Date: Thu Jul 22 18:35:52 1999 GMT
X-MyDeja-Info: XMYDJUIDantenangeli1962
Newsgroups: borland.public.jbuilder.java.swing
X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows NT)