• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HTML ouput in a editorPane. Exception when using 'bookmarks' links

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am trying to create a java application which generate a html document. This html is to be output withing a document needs to have an index. I am creating a simple scenario as follows:

editorPane.setText(
"<html>"
+ "<head>"
+ "<title>Test Bookmarks</title>"
+ "</head>"
+ "<hr>"
+ "<p>"
+ "<BR><font size=\"4\" face=\"Arial\"><em><a href=\"#Tag1\">1. Tag1 </a></em></ont>"
+ "<BR>"
+ "<BR>"
+ "<BR><br><br><p><font size=\"4\" face=\"Arial\"><em><font color=\"#0000ff\"><a name=\"Tag1\">Tag1</a></em><p></font>"
+ "<p>"
+ "</body>"
+ "</html>");

When I run the application, the output is as follows:

1. Tag1 -> this is the index



Tag1 -> this is a bookmark

What I need to achieve is that by clicking on '1. Tag1', I should go to the 'Tag1' bookmark. The HTML code is ok (I did a test using an actual htlm doc with the above html tags). The problem I have is that as soon as I hover the cursor over the '1. Tag1' tag, I get and exception as follows:

Exception occurred during event dispatching:
java.lang.NullPointerException
at testtags.editorPaneTags$2$1.run(editorPaneTags.java:90)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:178)
at java.awt.Dialog$1.run(Dialog.java:1045)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

The line of code that throws the exception is

editorPane.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(final HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) {
EventQueue.invokeLater(new Runnable() {
public void run() {
// Show hand cursor
SwingUtilities.getWindowAncestor(editorPane).setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
// Show URL as the tooltip
editorPane.setToolTipText(e.getURL().toExternalForm()); // -> EXCEPTION THROWN HERE
}
});

I used the same code to have a html document with links to a HTTP type url and that works fine. I am just having trouble with creating bookmark type Hyperlinks.

I am not an experience Java programmer and I am sure I am doing something wrong. Can anyone guide me on what I am doing wrong ? I am attaching the whole java code.

Many thanks.

mc




reply
    Bookmark Topic Watch Topic
  • New Topic