I have two methods: colorText()
and colorBackground()
. They both color the selected text fromjTextPane
, either its foreground or background. Now I would like to have another method that would set the whole text back to normal (with black foreground and white background).
How do I do that?
Asked
Active
Viewed 75 times
1
1 Answers
2
Given a 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);