Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextPane not reflecting changes  RSS feed

selvas kumars
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,
Here is the code snippet which gives me a problem..
On trying this code below i am able to add bold to the selected
portion of the text, but when i try to remove the bold portion in the textpane it is not getting removed from UI??What may be
the problem??
contentTextPane is the reference for the textpane.
set -- contentTextPane .setEditorKit(new HTMLEditorKit()) ;
you can put the following in an actionlistener for a button.
Try selecting a portion in the textpane and click the button ....
int startpostion = 0;
int mark = contentTextPane.getCaret().getMark();
int dot = contentTextPane.getCaret().getDot();
int end = 0;
startpostion =mark;
end = dot;
}else {
startpostion = dot;
end =mark;

Element element = contentTextPane.getStyledDocument().getCharacterElement(startpostion);
AttributeSet attrs = element.getAttributes();
SimpleAttributeSet simpleAttr = new SimpleAttributeSet();

contentTextPane.getStyledDocument().setCharacterAttributes(startpostion,end-startpostion, simpleAttr, true);
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!