如何将 jTextPane 中的整个(突出显示或不突出显示)文本设置为正常?
How to set the whole (highlighted or not) text in jTextPane back to normal?
我有两种方法:colorText()
和 colorBackground()
。它们都为 jTextPane
中的选定文本着色,无论是前景还是背景。现在我想有另一种方法可以将整个文本设置为正常(黑色前景和白色背景)。
我该怎么做?
给定一个 StyledDocument
, as shown here, you can invoke setCharacterAttributes()
with whatever style you want. The example below uses a default SimpleAttributeSet
, but you can use any AttributeSet
, such as the ones shown here.
f.add(new JButton(new AbstractAction("Clear") {
@Override
public void actionPerformed(ActionEvent e) {
doc.setCharacterAttributes(0, doc.getLength(), new SimpleAttributeSet(), true);
}
}), BorderLayout.SOUTH);
我有两种方法:colorText()
和 colorBackground()
。它们都为 jTextPane
中的选定文本着色,无论是前景还是背景。现在我想有另一种方法可以将整个文本设置为正常(黑色前景和白色背景)。
我该怎么做?
给定一个 StyledDocument
, as shown here, you can invoke setCharacterAttributes()
with whatever style you want. The example below uses a default SimpleAttributeSet
, but you can use any AttributeSet
, such as the ones shown here.
f.add(new JButton(new AbstractAction("Clear") {
@Override
public void actionPerformed(ActionEvent e) {
doc.setCharacterAttributes(0, doc.getLength(), new SimpleAttributeSet(), true);
}
}), BorderLayout.SOUTH);