【发布时间】:2014-02-08 01:25:14
【问题描述】:
我写了一个文本编辑器,将文本保存为 html。
我对粗体、斜体等样式没有任何问题,我唯一遇到的问题是当我按下回车键时它的行为方式。
它不是创建一条新的法线,而是创建一条额外的间隔线。我认为这与<p> 标签有关,但我不确定...
无论如何,这是我的问题的一个例子:
import java.awt.BorderLayout;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.text.html.HTMLEditorKit;
public class test extends JFrame {
public static void main(String[] args){
new test().open();
}
private void open() {
setSize(200, 200);
JEditorPane jp = new JEditorPane();
setLayout(new BorderLayout());
add(jp, BorderLayout.CENTER);
jp.setEditorKit(new HTMLEditorKit());
jp.setText("<html><body><p>hey</p><p>Write in here</p></body></html>");
setVisible(true);
}
}
有没有办法解决这个问题?
【问题讨论】:
-
你能贴出处理关键事件的代码吗?
-
@JuanManuel 我没有任何处理关键事件的代码:/
-
看看
HTMLDocumentEditor,引用here。
标签: java html swing jeditorpane