Win a copy of Penetration Testing Basics this week in the Security forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic


Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have been working with this for the last 5 hours and I can't get it right.

I have a JTextPane with a HTMLDocument , HTMLEditorKit.

When a user presses a button I insert <ul class="test"><li></li></ul> into the document and this works fine.

Now I wan't to edit the Attribute.CLASS in the ul element for another class.

I have tried everything. How can i replace the <ul class="test"> agains <ul class="test1">?

I would like to get the paragraphElement from the current CaretPosition.

int pos = JTextPane.getCaretPosition();
Element elem = HTMLDocument.getParagraphElement( pos );
SimpleAttributeSet s = new SimpleAttributeSet();
s.addattibute( HTML.Attribute.CLASS , "test1" );
HTMLDocument.setParagraphAttributes( elem.getStartOffset() , elem.getStopOffset() - elem.getStartOffset() , s , false );

Please help.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic