2

JEditorPaneHTMLDocumentおよびを使用してエディタを作成してい HTMLEditorKitます。エディターのスタイル属性を変更するためのさまざまなコンポーネントを含むツールバーがあります。それらの1つは、属性JComboBoxを変更することです。ZOOM_FACTOR以下のコードは、そのJComboBox値が変更されたときに実行されるコードです。

    final SimpleAttributeSet attrs = new SimpleAttributeSet();
    zoomCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String s = (String) zoomCombo.getSelectedItem();
            s = s.substring(1, s.length());
            double scale = new Double(s).doubleValue() / 100;
            editorPane.getDocument().putProperty("ZOOM_FACTOR", new Double(scale));

            try {
                StyledDocument doc = (StyledDocument) editorPane.getDocument();
                doc.setCharacterAttributes(0, 1, attrs, true);
                doc.insertString(0, "", null); // refresh
            } catch (Exception ex) {
                logger.error("Hata", ex);
            }
        }
    });

doc.setCharacterAttributes(0, 1, attrs, true);私の問題の根本が始まる行です。このコード行の実行後、が の の部分に<p-implied>追加されます。そして、これが起こった後、特定のパターンのイベントが発生すると、破損します。一緒に作成しない方法はありますか?そうでない場合、この問題の最善の回避策は何ですか?<head></head>HTML textJEditorPane.getTextHTML text<p-implied>

PS : JDK バグ システムで報告された古いものがあります。<p-implied>別の理由で報告されていますが、同じことが後で追加されていることも示されてい<head></head>ます。JTextPaneこのリンクで報告された問題は、クラス内の (のサブクラスJEditorPane) とsetCharacterAttributesメソッドを使用していることを知っていますが、そのメソッドは、私が内部で使用したのJTextPaneと同じメソッドも呼び出します。setCharacterAttributes

4

1 に答える 1