hello friends,
using the following code i am able to insert a specific text in the JTextPane.
public void append(Color c,
String s) { // better implementation--uses
// StyleContext
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY,
StyleConstants.Foreground, c);
int len = getDocument().getLength();
setCaretPosition(len); // place caret at the end (with no selection)
setCharacterAttributes(aset, false);
replaceSelection(s); // there is no selection, so inserts at caret
}
}
the append method can be called the followig way
JTextPane pane = new ColorPane();
String s = "replace";
pane.append(Color.red,s);
the problem here is the String s is getting inserted, but i need to replace String s with another occurance of s in the pane. please help.
- rohitrusty314