我正在使用 和创建一个编辑JEditorPane
器。我有一个工具栏,其中包含用于更改编辑器样式属性的各种组件。其中之一是更改属性。下面的代码是当值改变时执行的代码。HTMLDocument
HTMLEditorKit
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 text
. JEditorPane.getText
发生这种情况后,如果发生某种特定的事件模式,我的行为HTML text
就会被破坏。有什么办法不一起创作<p-implied>
吗?如果不是这样,那么解决此问题的最佳方法是什么?
PS:JDK Bug System 中有一些旧的报告。据报道,出于不同的原因,但那里也显示,后来<p-implied>
添加了相同的内容<head></head>
。我知道此链接中报告的问题在类中使用JTextPane
(的子类JEditorPane
)和setCharacterAttributes
方法,JTextPane
但该方法也调用了setCharacterAttributes
我在其内部使用的相同方法。