• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Problem with JEditorPane

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I fill the JEditorPane with a html-side
JEditorPane myPane = new JEditorPane("");
myPane.setPage("file:"+fileDirectory+"foo.html");
I add a hyperlink listener to the JEditorPane. Everytime when a link was hit and the site doesn't exist I show my own error-message :

When I am now hit the link Index the hyperlinkevent is fired nothing happends.
I looked a long time why nothing happends. I guess the reason is the method setText in the catch-block.
For debugging I changed the setPage()-method to setText("to the <a href=\"myIndex.html\">page</a> to the <a href=\"nofile.html\">Exception</a>"); in the try-Block. When I'm now click the Exception-Link, the IOException will execute.
When I'm now hit the other link after that, the text in the try-block is showing.
Ok so what I've found out is :
Exception => setText("asdsadsadsa"); -> hit link -> setPage() doesn't work
Exception => setText("asdsadsadsa"); -> hit link -> setText() work's
Exception => setPage("foo.html"); -> hit link -> setPage("foo.html") work's
What I'm doing wrong?
regards
Lars
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I just wondered: don't you have to set the Mime type of the JTextPane explicitely to "text/html".
Maybe I just missed where you are doing that and I also don't know if that will solve you're problem. For what the API says: the default mime type is plain not html.
Chantal
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
uhm, sorry. just read some more API. so the mime type is set by some methods automatically. that is, setPage will select "text/html".
" 3. The setPage method can be used to initialize the component from a URL. In this case, the content type will be determined from the URL, and the registered EditorKit for that content type will be set. "
Nevertheless, I would set the mime type explicitely, just to be sure.
The second point is: The JTextPane has to be editable(false). (Sorry, if I am telling you things you are already aware of!)
" Some kinds of content may provide hyperlink support by generating hyperlink events. The HTML EditorKit will generate hyperlink events if the JEditorPane is not editable (JEditorPane.setEditable(false); has been called)."
cheers
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had the same error a few days ago. My problem was that the URL was wrong. I solved it in that way:

Maybe this works for you too?
 
reply
    Bookmark Topic Watch Topic
  • New Topic