JEditorPane
I am loading a document into a JEditorPane using a setPage(url) function. The thing is that some files are very big and bulky so they take time to load.
Is there any way to determine whether the file has been loaded completely?
I want to highlight a particular word in the document when it's done loading, but since some files take time to load hence sometimes there are errors...
Is there a way to find out of the document/file has been completely loaded in the JEditorPane through coding?
# 1
Yes, if you attach an event listener to your JEditorPane, you will receive a "page property change" event when the document finishes loading. See the JEditorPane javadoc for details.
# 4
Yes dude I get the point..[:)].
That did come to my mind in an earlier situation, but often in actionListeners you can access only final variables hence this thought doesn't come to my mind in other scenarios thanks for that simple thing.. :D
Anyways, now what my problem has become after is that since I have handled the propertyChangeListener of the JEditorPane, and changed the done boolean value correspondingly...
Now how should I handle that else where?
I tried doing this :
JEditorPane.setPage(url);
while(done==false);
but it so happens that the code is now gettign stuck here!!!
since after calling the JEDitorPane.setPage(url) the propertyChangeEvent of the JEditorPane changes to "document" and hence done = false...
hence now the code is stuck within the while loop and the JEditorPane is not getting further anywhere to reach the 'done' :D
I know perhaps i am acting quite stupid in all of this and perhaps i am missing some really trivial thing, but it always happens, when one works on something for very long then the mind tends to get, you know..pretty much slow :D...too much cache in the mind makes the mind work slow and it missed critical things here and there and tends to make mistakes...
Just like what i am doing...
But I am trying to fight it out by taking occasional breaks ;)
Anyways. lets get past this problem for now...
# 5
The line:
while(done==false);
will block the event dispatching thread forever, as you have observed.
Do you really want to block your application until the document has finished loading? If so, then have the document load synchronously; this has been discussed in another thread. But it would be preferable to put any code which needs to be executed when the document has finished loading into your event listener, rather than trying to execute it right after the call to JEditorPane.setPage().
Geoff
# 6
You miss the whole point of using a PropertyChangeListener.
You load the page normally and don't do any highlighting.
The code for highlighting is added to the PropertyChangeListener. You should be aware that this event fires when the main page has been loaded, not when all the pages are loaded. So if you need to load images, these images will be loaded as the main page is parsed, but it shouldn't be a problem for your requirement.
# 7
camickr, thanks a lot for that advice.Now i am able to do what I want perfectly. Thanks a lot for your help.I handled the highlighting in the propertyChangeListener as adviced by camickr, that is indeed the most simple and appropriate approach. :)