🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Can't make hyperlink work in JEditorPane

#12621
From: Julian Monypenny
Date: Wed, 02 Dec 1998 00:00
51 lines
1931 bytes
Berco,

To make a hypertext link work, first add a hypertext link listener to your
JEditorPane in the  jbInit method:

  fileEditor.addHyperlinkListener(this);

Override the listener's update method as follows:

 public void hyperlinkUpdate(HyperlinkEvent e) {
  if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
   openPage(e.getURL().toString());
  }

Finally, code an openPage method similar to the one shown below:

 private void openPage(String file) {
  try {
   fileEditor.setContentType("text/plain");
   fileEditor.setPage(file);
   fileViewport.repaint();
  }
  catch (IOException e) {
   // Error
  }

It's a good idea to use a vector to hold a stack of opened pages so you can
provide the facility to navigate through them.

With regard to frames, the version of Swing I'm using doesn't support them,
although someone else may have had more luck with the latest version.

Regards,

Julian

-=(CyBerCo)=- wrote in message <743i6j$q059@forums.borland.com>...
>______________________________________________________________________
>Hi,
>
>I have a JEditorPane displaying a html-page, but I don't know how I can
make
>a link in the html-page work. I would also like to  know how to make a
>html-page with frames work in a JEditorPane.
>
>Thanx in advance!
>Berco
>______________________________________________________________________
>
>
>
Technical Details
Message-ID: <744hrc$r6g3@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <743i6j$q059@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,dc0e30e46a16de6d
X-Google-Attributes: gid111d45,public
From: "Julian Monypenny" <jmonypenny@news400.com>
Subject: Re: Can't make hyperlink work in  JEditorPane
Date: 1998/12/02
Message-ID: <744hrc$r6g3@forums.borland.com>
X-Deja-AN: 418022752
References: <743i6j$q059@forums.borland.com>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.swing