1
我正在使用JEditorPane
來顯示一些文本。問題是我不能添加多行。無法在JEditorPane中添加多行
我的代碼現在
public class Window extends JFrame {
private JEditorPane text = new JEditorPane();
public Window() {
setLayout(new BorderLayout());
setTitle("test");
setSize(500, 350);
setResizable(false);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLocationRelativeTo(null);
text.setEditable(false);
text.setContentType("text/html");
text.setText("<b>Some bold text</b><br>");
text.setText(text.getText() + "<br>Some text that is not bold but here <b>it is</b>");
getContentPane().add(text, BorderLayout.CENTER);
setVisible(true);
}
}
當它處於同一直線上療法是沒有問題的,<br>
創建一個新行。但是,如果它是在多個聲明中,我不能得到它的工作。
它需要在多個語句中,因爲每個語句稍後將成爲if
條件。
我怎樣才能讓它做多行?
所以當我做'text.setText(文字。 getText + bla bla);'它不重置'JEditorPane'中的文本嗎? – Chax 2014-10-31 19:51:23
不,它不會。相反,它將用#
替換原文bla bla'。因此'