在JTextArea或JTextPane中设置文本样式 [英] Styling text in a JTextArea or JTextPane
问题描述
public static void main(String [] args){
JFrame j =新的JFrame(Hello!);
j.setSize(200,200);
JTextPane k = new JTextPane();
k.setText(< html>< strong>嘿!< / strong>< / html>);
j.add(k);
j.setVisible(true);
}
当用户想要在JTextPane中设置样式时,与界面交互,但到目前为止,它只是返回字符串仍然在HTML!帮助!
如果您想在<一个href =http://docs.oracle.com/javase/tutorial/uiswing/components/editorpane.html =nofollow noreferrer> JTextPane ,那么你必须设置为 JTextPane#setContentType(text / html ); ,示例这里
编辑:
用于 JEditorPanes / JTextPanes
am方法是不使用 Html语法
Basically, I have a JTextPane to hold some text which I wish to style. JTextArea would have been better for me to use but I'm told you cannot style the text in these?
However, the JTextPane doesn't seem to style properly. For example, the following code is just returned with the HTML included:
public static void main(String[] args) {
JFrame j = new JFrame("Hello!");
j.setSize(200,200);
JTextPane k = new JTextPane();
k.setText("<html><strong>Hey!</strong></html>");
j.add(k);
j.setVisible(true);
}
I want to be able to just style some text in a JTextPane when a user interacts with the interface, but so far, it just returns the string with the HTML still in! Help!
If you want to diplaying Html
contents in the JTextPane then you have to set for JTextPane#setContentType("text/html");, example here
EDIT:
for JEditorPanes / JTextPanes
is there another way by implements StyledDocument, MutableAttributeSet and with customized Highlighter, example here
a.m. way is without using Html syntax
这篇关于在JTextArea或JTextPane中设置文本样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!