wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes HTML ouput in a editorPane. Exception when using 'bookmarks' links Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "HTML ouput in a editorPane. Exception when using Watch "HTML ouput in a editorPane. Exception when using New topic
Author

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

mc cipolla
Greenhorn

Joined: Mar 13, 2013
Posts: 1
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




 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HTML ouput in a editorPane. Exception when using 'bookmarks' links
 
Similar Threads
IOException when trying to load from binary file
Error in FileReader
Implementing KeyListener interface
Threaded JTextArea Update
? Trying to implement ListSelectionModel on an AbstractTableModel