I have a JTextPane (or JEditorPane, I can use either no problem). How can I change the font of a selected area to a specific font?
textpane.getSelectedText().setFont() won’t work. (Even with font-family)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can change JTextPane’s font only as a whole, it doesn’t do rich text.There’s a
Documentunderneath JEditorPane (and apparently JTextPane too), which you get a hold of withgetDocument(). You want to cast that to aStyledDocumentif you can, and then you can do things likesetCharacterAttributesto a given run of characters.There are some (hopefully) helpful examples in the Java tutorial at http://java.sun.com/docs/books/tutorial/uiswing/components/editorpane.html .