I have textpane getting generated. i need to supercript the text when the text is selected and during click of superscript button, i need to superscript the text. if the text is already superscripted, it needs to unsuperscript the text. My problem is i am able to superscript the text, but unable to restore back. I am checking for the isSuperscript condition, but then every time it returns the value as true and sets the text as superscript. below is the code i am using, can anyone tell me how i can reset the superscripted text.
SimpleAttributeSet sasText = new SimpleAttributeSet(parentTextPane.getCharacterAttributes());
System.out.println("character set 1 " + sasText.toString());
if ( StyleConstants.isSuperscript(sasText) ){
System.out.println("already super");
StyleConstants.setSuperscript(sasText, false);
} else {
System.out.println("needs super");
StyleConstants.setSuperscript(sasText, true);
}
int caretOffset = parentTextPane.getSelectionStart();
parentTextPane.select(caretOffset, caretOffset + textLength);
HTMLDoc.setCharacterAttributes(selStart,textLength,sasText, false);
parentEkit.refreshOnUpdate();