如何阻止java HTMLEditorKit自动关闭我的标记
我有一个问题,我的粗体标记被java HTMLEditorKit自动关闭,我尝试了好几次来解决这个问题,但我被困在这里。 我用的是绝地武士 当我按下粗体按钮时,它应该保持标签打开,直到我再次单击按钮 这是我的密码如何阻止java HTMLEditorKit自动关闭我的标记,java,jeditorpane,Java,Jeditorpane,我有一个问题,我的粗体标记被java HTMLEditorKit自动关闭,我尝试了好几次来解决这个问题,但我被困在这里。 我用的是绝地武士 当我按下粗体按钮时,它应该保持标签打开,直到我再次单击按钮 这是我的密码 HTMLEditorKit hkit = new HTMLEditorKit(); HTMLDocument doc = new HTMLDocument(); editorPane.setEditorKit(hkit); editorPane.setD
HTMLEditorKit hkit = new HTMLEditorKit();
HTMLDocument doc = new HTMLDocument();
editorPane.setEditorKit(hkit);
editorPane.setDocument(doc);
/*editorPane.setText(htmlString);*/
contentPane.add(panel_2, BorderLayout.SOUTH);
bbold.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
int start = editorPane.getSelectionStart();
int end = editorPane.getSelectionEnd();
if (start == end) { // x=y
if (btrigger == false) {
try {
hkit.insertHTML(doc, start, "<b>\u0000", 0, 0, HTML.Tag.B);
btrigger = true;
} catch (BadLocationException | IOException e) {
e.printStackTrace();
}
}
else {
try {
hkit.insertHTML(doc, start, "</b>\u0000", 0, 0, HTML.Tag.B);
btrigger = true;
} catch (BadLocationException | IOException e) {
e.printStackTrace();
}
}
}
if (start > end) { // x<y
if (btrigger == false) {
}
}
}
});
HTMLEditorKit hkit=新的HTMLEditorKit();
HTMLDocument doc=新的HTMLDocument();
setEditorKit(hkit),;
editorPane.setDocument(doc);
/*editorPane.setText(htmlString)*/
contentPane.add(面板2,BorderLayout.SOUTH);
bbold.addActionListener(新ActionListener(){
已执行的公共无效操作(操作事件arg0){
int start=editorPane.getSelectionStart();
int end=editorPane.getSelectionEnd();
如果(开始==结束){//x=y
如果(btrigger==false){
试一试{
hkit.insertHTML(doc,start,“\u0000”,0,0,HTML.Tag.B);
btrigger=true;
}捕获(BadLocationException | IOException e){
e、 printStackTrace();
}
}
否则{
试一试{
hkit.insertHTML(doc,start,“\u0000”,0,0,HTML.Tag.B);
btrigger=true;
}捕获(BadLocationException | IOException e){
e、 printStackTrace();
}
}
}
如果(开始>结束){//x