after trying to debug the below exception for a couple hours,
it seems JEditorPane does not like certain characters?
the code
...
sb.append (str);
txtMessage.setText ("<font color=red>" + sb.toString() +
"</font><br>");
...
This would only cause the exception when str contained the "<" and ">"
characters. such as when str = str + "<User1>";
I removed the Arrowheads from str to get it to work. Hope it helps
someone else.
------------- exception -----------------------------------------
java.lang.ArrayIndexOutOfBoundsException: 0
at javax.swing.text.BoxView.getOffset(BoxView.java:1079)
at javax.swing.text.BoxView.childAllocation(BoxView.java:669)
at javax.swing.text.CompositeView.getChildAllocation(CompositeView.java:215)
at javax.swing.text.BoxView.getChildAllocation(BoxView.java:427)
at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.calculateViewPosition(BasicTextUI.java:1856)
at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.layoutContainer(BasicTextUI.java:1832)
at java.awt.Container.layout(Container.java:1020)
at java.awt.Container.doLayout(Container.java:1010)
at java.awt.Container.validateTree(Container.java:1092)
at java.awt.Container.validateTree(Container.java:1099)
at java.awt.Container.validateTree(Container.java:1099)
at java.awt.Container.validate(Container.java:1067)
at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:353)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:116)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
> txtMessage.setText ("<font color=red>" + sb.toString() +
>"</font><br>");
You want to entify strings. See
http://mindprod.com/products.html#ENTITIES
and
http://mindprod.com/products.html#QUOTER
Quoter also contains a class for stripping tags out of a string, and
for converting entities back into single characters.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
So you mean HTML support in Java only accepts valid HTML?
That seems like the right approach to me.
--
Mike W
> So you mean HTML support in Java only accepts valid HTML?
I tried to display this document in a Swing component recently..
<http://www.un.org/Overview/rights.html>
<http://validator.w3.org/check?uri=http://www.un.org/Overview/rights.html>
The Swing component gagged a few times before
suffering a sustained head spin with associated
projectile vomitting.. ;-)
--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
>So you mean HTML support in Java only accepts valid HTML?
>That seems like the right approach to me.
It greatly adds to the complexity of the rendering engine to allow
invalid HTML.
The problem you have in ordinary browsers is people test with IE which
is very forgiving, but then the HTML does not work other places.
Competition leads to greater and greater sloppiness, and more and more
overhead in browsers to deal with crap.
Inside Java, you don't have to deal with invalid HTML. So it makes
sense to have a streamlined engine that works only with validated
HTML. The catch is there is no easy way to run a validator on all the
HTML embedded in a Java program. Much of it does not even exist until
run time.
When Jesus comes, the first thing He will do is legislate a compact
binary format for HTML that is free from Error.
why should that give a problem?
<font color=red><User1></font><br> seems ok.
html tags can be used like that.
problem should be when it has only the opening or the
closing tag. Then it will mess up with the html.
<font color=red>User1></font><br>
<font color=red><User1</font><br>
> So you mean HTML support in Java only accepts valid HTML?
> That seems like the right approach to me.
>
> -- Mike W
On a related note, Has anyone observed whether html slows
down the program by hours.
In one of my programs, I had used Jbuttons with html
setText(). It was damn slow.
Then someone who was testing it beta, removed all html and
changed the buttons to labels, and it is running like anything.
Could that be because or html and/ or buttons?
--
Rawat
As I understand it, several Mb of classes
need to be loaded (in addition to the usual
core) before HTML rendering can be done.
This leads to a singificantly slower *startup*
time, but should ne pretty much as quick at
changing text once the relevant classes are
loaded.
Of course, a simple test would help
distinguish where the bottlenecks lie.
Do time dumps throughout 2 programs.
One that displays a button w/plain text,
then changes the text 1000 times, another
with HTML formatted text that does the same.
<snip>
>
> So you mean HTML support in Java only accepts valid HTML?
> That seems like the right approach to me.
It does at first until you consider user input.
Well validate it then!
--
Mike W
And, of course, once you _do_ consider user input, you quickly
conclude that you should run that input through a
plain-text-to-HTML-entities filter before ever even _considering_
putting it into your GUI.
Cheers
Bent D
--
Bent Dalager - b...@pvv.org - http://www.pvv.org/~bcd
powered by emacs