wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes Swing - strange behaviour on text insert into a HTML pane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Swing - strange behaviour on text insert into a HTML pane" Watch "Swing - strange behaviour on text insert into a HTML pane" New topic
Author

Swing - strange behaviour on text insert into a HTML pane

sean van buggenum
Greenhorn

Joined: May 16, 2008
Posts: 7
Hi all,

I am trying to fix a problem on inserting a span tag into an existing html page (in an EDITABLE JEditorPane).

The behaviour:

Assuming the cells in a table (3 rows, 2 columns) are numbered from 1 to 6, with cell one being the top left most, cell 2 top right, cell 3 middle left, etc.

1. Inserting the text "<span></span>" in cell 4 causes during any attempt to later type into cell 5 the characters to be appended instead into cell 4, directly after the close span tag.
2. The insertion in the first place behaves strange. If I have the caret positioned for cell 5 so that I can insert there
(via the function void javax.swing.text.html.HTMLEditorKit.insertHTML(HTML Document doc, int offset, String html, int popDepth, int pushDepth, Tag insertTag) )
even though the caret position is visible in cell 5, the insertion seems to take place in cell 4.

I can sort of compensate for this by adding 1 to the offset. However, then when inserting into a line of text, for example, "the quick red fox jumped over the lazy dog"
I insert directly before the 'j' in 'jumped', the insertion looks like this "the quick red fox j<span>..</span>umped over the lazy dog"
So that is no solution.

IMPORTANT!
Just to prove it is not the span tag causing the trouble, if this span tag already exists in a cell on 'Load' of the html file, the strange behaviour is not observed.

Something is going wrong here. It is me? Or is it a bug?

Please help!!

Here is a test app, and the test html you can use (place in current directory).

Please test like this:

1. run application (the html should be loaded into the pane)
2. the span tag is programmed to automatically insert at cell 4 (by using the +1 method on the insert)
3. another span tag was already existing in the html file, at cell 8
4. Attempt to type into cell 5
result: the text appears instead at cell 4
5. Type into cell 9
result: the text correctly is entered into cell 9

See the difference!!

Help!


The test java app:


Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2152
    
    7
Be Forthright When Cross Posting To Other Sites

Also posted in the Sun forums.
sean van buggenum
Greenhorn

Joined: May 16, 2008
Posts: 7
geez... All i am getting is rules here, and no help.
And i seem to break them all.
I am sorry. Didn't mean it.
I feel I am a good net citizen, and would of course share any answer(s) on any or all forums I post on. That goes without saying.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Swing - strange behaviour on text insert into a HTML pane
 
Similar Threads
Copy n' Paste in JEditorPane wraps text in new css..?
missing the content when saving HTML from JEditorPane.write(..)
Frames in JEditorPane
Insert html
JEditorPane nbsp handling error ?