JTextArea - Selected Text > Bold, Ital., Underlined

Hello,

I have a word processing program where I want the user's selected text to become bold when the bold button is pressed, but I can't figure out how to set the selected text as something else. JTextArea has a method:

textArea.getSelectedText()

that returns a String, but I can't quite figure out how to replace it with the new text.

Please help.

Thank you!

[400 byte] By [keseldudea] at [2007-11-27 8:20:21]
# 1
Use JTextPane instead of JTextArea.Then you can replace the selected text with styled text.Read the tutorial: http://java.sun.com/docs/books/tutorial/uiswing/components/editorpane.html
Rodney_McKaya at 2007-7-12 20:08:38 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thanks, but I'm not quite familiar with JTextPane, and I use textArea.append() a lot in my program; JTextPane doesn't have an append() method.
keseldudea at 2007-7-12 20:08:38 > top of Java-index,Desktop,Core GUI APIs...
# 3
> a lot in my program; JTextPane doesn't have an append() method. Then write your own. Look at the source code for the JTextArea.append(...) method.
camickra at 2007-7-12 20:08:38 > top of Java-index,Desktop,Core GUI APIs...
# 4
Where do you get the source?
keseldudea at 2007-7-12 20:08:38 > top of Java-index,Desktop,Core GUI APIs...
# 5
Its in a file src.zip that comes with the JDK. At least thats where is was in JDK1.4.2. Read the documentation of the JDK and I'm sure you will find it.
camickra at 2007-7-12 20:08:38 > top of Java-index,Desktop,Core GUI APIs...
# 6
Quick question: If I'm using Eclipse, where would it be?
keseldudea at 2007-7-12 20:08:38 > top of Java-index,Desktop,Core GUI APIs...
# 7

public void append(String str) {

Document doc = getDocument();

if (doc != null) {

try {

doc.insertString(doc.getLength(), str, null);

} catch (BadLocationException e) {

}

}

}

Rodney_McKaya at 2007-7-12 20:08:38 > top of Java-index,Desktop,Core GUI APIs...
# 8
By now I found it, but thanks anyway :-)
keseldudea at 2007-7-12 20:08:38 > top of Java-index,Desktop,Core GUI APIs...