1

我有一个问题,我的粗体标签被 java HTMLEditorKit 自动关闭,我尝试了几次来解决这个问题,但我被困在这里。我正在使用 JEditorPane 当我按下粗体按钮时,它应该保持标签打开,直到我再次单击该按钮这是我的代码

    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) {
                }
            }
        }
    });
4

0 回答 0