Java JTextPane Change Font of Selected Text

后端 未结 2 1908
梦毁少年i
梦毁少年i 2021-01-13 20:53

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()

2条回答
  •  遥遥无期
    2021-01-13 21:10

    You can do this by using JTextPane. It is impossible to do this using JTextArea. . Here is a best example on how to use JTextPane.

    Sample: http://download.oracle.com/javase/tutorial/uiswing/components/editorpane.html

    Code: http://download.oracle.com/javase/tutorial/uiswing/examples/components/TextSamplerDemoProject/src/components/TextSamplerDemo.java

提交回复
热议问题