Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / February 2005

Tip: Looking for answers? Try searching our database.

HyperlinkListener  and < ahref="xy.html" target="framexy" >

Thread view: 
rolf gabler - 15 Feb 2005 17:45 GMT
Hi,
I got an application which sould show a html-file
as frameset, with a navigation frame in a tabbedPanel
I built a class extended by JPanel with a JEditorPane
and so far.

the result is that a link like:
<a href="x.html" target="mainframe">
will not be interpreted correct,
the frameset disapear and only the
link-site is shown.
I believe this could be a problem with my HyperlinkListener, because
when I use the HTMLFrameHyperlinkEvent and the framset
is shown in a JFrame as popup correct and all links are
working (I put the code below this post)

I add the HyperlinkListener in the following way,
which isn't able to handle a frameset
public class HTMKpnl{
...
try{
...
myJEditPnl.setEditable(false);
myJEditPnl.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
 if(e.getEventType()==HyperlinkEvent.EventType.ACTIVATED)
  try {
    myJEditPnl.setPage(e.getURL());
  }
  catch(Exception x) {
    System.out.println("Hyperlink listener
             error is " + x.getMessage());            
  }
 }}
);
JScrollPane scroller = new JScrollPane();
JViewport vp = scroller.getViewport();
vp.add(myJEditPnl);
add(scroller, BorderLayout.CENTER);
}
catch (MalformedURLException e) {}
catch (IOException e) {}

what is going wrong?

best regards
Rolf

#####this code works as it has to do####

public HyperlinkListener createHyperLinkListener() {
  return new HyperlinkListener() {
  public void hyperlinkUpdate(HyperlinkEvent e) {
     if (e.getEventType() ==
          HyperlinkEvent.EventType.ACTIVATED) {
          if (e instanceof
                HTMLFrameHyperlinkEvent) {              
               ((HTMLDocument)html.getDocument()
                  ).processHTMLFrameHyperlinkEvent(
                  (HTMLFrameHyperlinkEvent)e);
        } else {
      try {
       myJEditPnl.setPage(e.getURL());
     } catch (IOException ioe) {
        System.out.println("InpuOutputError " + ioe);
      }
   }
}
}
);

Folgetext zu diesem Beitrag schreiben
John McGrath - 15 Feb 2005 19:31 GMT
> I got an application which sould show a html-file
> as frameset, with a navigation frame in a tabbedPanel
> I built a class extended by JPanel with a JEditorPane
> and so far.

I do not think that the HTMLEditorKit supports FrameSets.  It supports
HTML 3.2, whereas FrameSets were added in HTML 4.0.  (Actually,
HTMLEditorKit  does support some of the HTML 4.0 features, but not
FrameSets, AFAIK.)

Signature

Regards,

John McGrath

rolf gabler - 16 Feb 2005 07:54 GMT
> > I got an application which sould show a html-file
> > as frameset, with a navigation frame in a tabbedPanel
[quoted text clipped - 5 lines]
> HTMLEditorKit  does support some of the HTML 4.0 features, but not
> FrameSets, AFAIK.)

Hi John,
nice to get your answers !
but strange is that when I use the code below
for creating a popup-frame - the frameset is shown and works
correct. I didn't implement the HTMLEditorKit.

I use it for j3d, when a 3d object is picked the
frame pop up and show the html file corresponding
to that 3dobject. And it works without any problems,
neither the heavy-lightweight problem is present,
when my JFrame pops in front of my canvas 3d
(I believe that the final container of the JFrame is heavyweight..
but I am unsure to this...just lucky that it seems to be working)
anyway here's the code to display a Frameset HTML inside a JFrame,
which worked with 1.4.2_++ and j3d 1.3.1 (I didn't try older ones)
on win2k - winxp - win98

best regards
Rolf

<code to show a Frameset-HTML>

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import javax.swing.border.*;
import javax.swing.colorchooser.*;
import javax.swing.filechooser.*;
import javax.accessibility.*;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.util.*;
import java.io.*;
import java.applet.*;
import java.net.*;

public class HTMLframe extends JFrame{

JEditorPane html;
public static void main(String[] args) {
 HTMLframe demo = new HTMLframe(args[0]);
 demo.getContentPane().setLayout(new BorderLayout());
 demo.setSize(640,480);
 demo.setVisible(true);
 }
 public HTMLframe(String path) {
 try {
  URL url = null;
   try {
    url = getClass().getResource(path);
   } catch (Exception e) {
     System.err.println("Pfad falsch oder Datei existiert nicht " + path);
     url = null;
   }
   if(url != null) {
      html = new JEditorPane(url);
      html.setEditable(false);
      html.addHyperlinkListener(createHyperLinkListener());
      JScrollPane scroller = new JScrollPane();
      JViewport vp = scroller.getViewport();
      vp.add(html);
      getContentPane().add(scroller, BorderLayout.CENTER);
   }
   } catch (MalformedURLException e) {
     System.out.println("Malformed URL: " + e);
   } catch (IOException e) {
     System.out.println("IOException: " + e);
   }
   }

   public HyperlinkListener createHyperLinkListener() {
     return new HyperlinkListener() {
    public void hyperlinkUpdate(HyperlinkEvent e) {
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
         if (e instanceof HTMLFrameHyperlinkEvent) {           
     ((HTMLDocument)html.getDocument()).processHTMLFrameHyperlinkEvent(
       (HTMLFrameHyperlinkEvent)e);
     } else {
       try {
        html.setPage(e.getURL());
     } catch (IOException ioe) {
       System.out.println("InpuOutputError " + ioe);
    }
    }
    }
    }
    };
   }
   
}
John McGrath - 16 Feb 2005 13:46 GMT
> but strange is that when I use the code below
> for creating a popup-frame - the frameset is shown and works
> correct. I didn't implement the HTMLEditorKit.

JEditorPane automatically installs an EditorKit based on the content-type
of the document that you load it with.  For HTML documents, that is an
HTMLEditorKit.

I just tried displaying some FrameSets and it appears to work somewhat, so
I guess I was wrong on that.  However, it did blow up a lot with CSS
errors when I tried to load the main J2SE JavaDocs.  It has been a while
since I tried using a JEditorPane for serious HTML, so I probably cannot
help much here.

I will say that I have found that JEditorKit is not exactly a robust HTML
viewer.  If you want to use it to display your own HTML, then you can make
sure to only use things that work well.  However, I long ago concluded
that using it for arbitrary HTML on the web is a non-starter.

Signature

Regards,

John McGrath

rolf gabler - 17 Feb 2005 11:47 GMT
> > but strange is that when I use the code below
> > for creating a popup-frame - the frameset is shown and works
[quoted text clipped - 3 lines]
> of the document that you load it with.  For HTML documents, that is an
> HTMLEditorKit.

but it seems to be that the HTMLFrameHyperlinkEvent is recognizing
the frameset and interprete it in a correct way, if there's nothing
else then Lowlevel HTML - which is all I need, just pictures and
some text and I Like to have framesets... the faq of this group
gave more common hints... so the solution is still a research value..

> I just tried displaying some FrameSets and it appears to work somewhat, so
> I guess I was wrong on that.  However, it did blow up a lot with CSS
> errors when I tried to load the main J2SE JavaDocs.  It has been a while
> since I tried using a JEditorPane for serious HTML, so I probably cannot
> help much here.

try the HTML code below and you'll see a correct displayed frameset
with href...target= which works,
so I search for a way to get the "function" of the
HTMLFrameHyperlinkEvent
into my panel...
because if I use HyperlinkEvent in my panel and add it to the
tabbedPanel
it displays only the last given html-file of the frameset without any
pictures or other formats also no cr/lf (<br>)is made... only the
background color remind me that this could be HTML...
if I set the navigation html as the last frame all will be shown in a
tiny panel but the targeted-link won't work...
could it be possible, that the way I implement the HyperlinkListener
is only usable for rtf ?

the panel which display not the defiened HTML (..??..) is here

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.html.*;
import javax.accessibility.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.net.*;

public class HTMLpanel extends JPanel{

   JEditorPane htmlp;
public static void main(String[] args) {
    HTMLpanel demo = new HTMLpanel(args[0]);
    JFrame frame = new JFrame();
       frame.getContentPane().setLayout(new BorderLayout());
    frame.setSize(640,480);
    frame.getContentPane().add(demo, BorderLayout.CENTER);
    frame.setVisible(true);
   }
   public HTMLpanel(String path) {
       try {
     URL url = null;
     try {
           url = getClass().getResource(path);
         } catch (Exception e) {
        System.err.println("wrong path!! " + path);
       url = null;
         }
         if(url != null) {
           htmlp = new JEditorPane(url);
           htmlp.setEditable(false);
           htmlp.doLayout();
           html.addHyperlinkListener(new HyperlinkListener () {
            public void hyperlinkUpdate(final HyperlinkEvent e) {
              if (e.getEventType() ==
HyperlinkEvent.EventType.ACTIVATED) {
               SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                 try {
                   htmlp.setPage(e.getURL());
                 } catch (IOException io) {
                   System.out.println("NO HOPE");
                 }
              }
            });
           }
           }
          });
         JScrollPane scroller = new JScrollPane();
     scroller.getViewport().add(html);
         add(scroller, BorderLayout.CENTER);
         }
       } catch (MalformedURLException e) {
           System.out.println("Malformed URL: " + e);
       } catch (IOException e) {
           System.out.println("IOException: " + e);
       }
   }
}

> I will say that I have found that JEditorKit is not exactly a robust HTML
> viewer.  If you want to use it to display your own HTML, then you can make
> sure to only use things that work well.  However, I long ago concluded
> that using it for arbitrary HTML on the web is a non-starter.

Yep, thats what I plan to do, just very simple html-files no plugins
and so far just simple formated text with pictures. I'll write my own
HTML writer to support this.

just for your interest that HTMLFrame is also able to show
a HTML ImageMap but this will ignore the <a href=".." target=..
it'll not working using frame-technic.

if you got any further hints I am greedy to get them
best regrads
rolf

now following the sample-frameset:

The HTML code which is correct diplayed in the HTMLFrame and incorrect
displayed in the panel is:
index.html
<html>
<head><title>test</title></head>
<frameset cols="205,*" frameborder="no">
<frame src="navigation.html" name="navi">
<frame src="start.html" name="main">
</frameset>
<noframes>Your browser is not able to show the
frameset</noframes></html>
</html>

navigation.html

<html>
<head>
</head>
<body bgColor="#FCBF49">
<a HREF="00.html" target="main" >Start</a><br>
<a HREF="01.html" target="main" ><IMG SRC="01.gif"
BORDER="0"></a><br>
<a HREF="02.html" target="main" ><IMG SRC="02.gif"
BORDER="0"></a><br>
<a HREF="03.html" target="main" ><IMG SRC="03.gif"
BORDER="0"></a><br>
<a HREF="04.html" target="main" ><IMG SRC="04.gif"
BORDER="0"></a><br>
<a HREF="05.html" target="main" ><IMG SRC="05.gif"
BORDER="0"></a><br>
<a HREF="06.html" target="main" ><IMG SRC="06.gif"
BORDER="0"></a><br>
<a HREF="start.html" target="main" >Start</a><br>
</body>
</html>

start.html
<html>
<head>
<title>start</title>

</head>
<body bgcolor="#FAF6ED">

<table border=0>
<tr>
<td>
<font face="Helvetica" >
<b><big> Start</big></b><br>
</font>
<font face="Helvetica" size=3>
any text
<p><b><i>source</i></b></p>
</font>
</td>
<td><img src="00.gif" >
</td>
</tr>
</body>
</html>
John McGrath - 19 Feb 2005 18:58 GMT
> if you got any further hints I am greedy to get them

Sorry - I have nothing.

Signature

Regards,

John McGrath

Thomas Weidenfeller - 16 Feb 2005 07:52 GMT
> Hi,
> I got an application which sould show a html-file
[quoted text clipped - 7 lines]
> the frameset disapear and only the
> link-site is shown.

See the groups FAQ.

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

rolf gabler - 17 Feb 2005 11:52 GMT
..

> See the groups FAQ.
>
> /Thomas

Hi Thomas,
there wasn't anything more special about why
that kind of link is working using HTMLFrameHyperlinkEvent
and why it isn't working using the HyperlinkEvent
...should be anything to do with the parser that
is used by those events...
so if you got further hints I am very interested
to solve this.
btw. that HTML View is ONLY for displaying
selfmade simple HTML, refer to my last posting
to realize the whole problem.
best regards
rolf


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.