Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

beware: herein demons lie with JEditorPane

3 views
Skip to first unread message

bad_knee

unread,
Jul 5, 2004, 9:20:11 PM7/5/04
to
Just to pass it along...

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)

Roedy Green

unread,
Jul 5, 2004, 9:52:11 PM7/5/04
to
On 5 Jul 2004 18:20:11 -0700, bl8...@yahoo.com (bad_knee) wrote or
quoted :

> 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.

VisionSet

unread,
Jul 6, 2004, 11:54:01 AM7/6/04
to

"bad_knee" <bl8...@yahoo.com> wrote in message
news:e817ca4d.0407...@posting.google.com...

> Just to pass it along...
>
> 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>";
>

So you mean HTML support in Java only accepts valid HTML?
That seems like the right approach to me.

--
Mike W


Andrew Thompson

unread,
Jul 6, 2004, 11:47:03 AM7/6/04
to
On Tue, 06 Jul 2004 15:54:01 GMT, VisionSet wrote:

> 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

Roedy Green

unread,
Jul 6, 2004, 2:15:50 PM7/6/04
to
On Tue, 06 Jul 2004 15:54:01 GMT, "VisionSet" <sp...@ntlworld.com>
wrote or quoted :

>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.

V S Rawat

unread,
Jul 6, 2004, 4:54:56 PM7/6/04
to
VisionSet wrote:
> "bad_knee" <bl8...@yahoo.com> wrote in message
> news:e817ca4d.0407...@posting.google.com...
>
>> Just to pass it along...
>>
>> 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>";

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

Andrew Thompson

unread,
Jul 7, 2004, 6:23:47 AM7/7/04
to
On Wed, 07 Jul 2004 02:24:56 +0530, V S Rawat wrote:
..

> On a related note, Has anyone observed whether html slows
> down the program by hours.

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.

bad_knee

unread,
Jul 7, 2004, 8:06:01 AM7/7/04
to
"VisionSet" <sp...@ntlworld.com> wrote in message news:<tWzGc.66$rS4...@newsfe2-win.ntli.net>...

> "bad_knee" <bl8...@yahoo.com> wrote in message
> news:e817ca4d.0407...@posting.google.com...
> > Just to pass it along...

<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.

VisionSet

unread,
Jul 7, 2004, 10:04:14 AM7/7/04
to

"bad_knee" <bl8...@yahoo.com> wrote in message
news:e817ca4d.04070...@posting.google.com...

Well validate it then!

--
Mike W


Bent C Dalager

unread,
Jul 7, 2004, 10:32:44 AM7/7/04
to
In article <e817ca4d.04070...@posting.google.com>,

bad_knee <bl8...@yahoo.com> wrote:
>
>It does at first until you consider user input.

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

0 new messages