I'm using a JEditorPane as a web browser, and I need to be able to detect any failure to load the page of a properly formatted URL (i.e. doesn't throw MalformedURLException
). I use PropertyChangeListener (with property name "page") for when a page has finished loading, but it does nothing when I enter some random gibberish like http://geowfkwpf.com/
, and neither does any other listener that can be applied to JEditorPane (I tried them all).
Edit: also, there's a "plong" sound effect about 2 seconds after I enter the link, presumably when the program has concluded that it cannot connect, so there must be some way of "listening" (ha) to it. By the way, if there's a way to disable that sound please let me know, but that's a tertiary concern.
I figured it out. The line myJEditorPane.setContentType("text/html");
(it's "text/plain"
by default) causes myJEditorPane.setPage(url)
to not throw UnknownHostException
but instead make the "plong" sound. I don't know why, I don't know how you solve the problem if you need to set the content type to html, and I don't know what setting the content type to html does, but hey, I solved the problem for me.