import java.awt.Color;
import javax.swing.JTextPane;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
public class Main {
public static void main(String[] argv) throws Exception {
JTextPane textPane = new JTextPane();
Style style = textPane.addStyle(null, null);
StyleConstants.setForeground(style, Color.red);
textPane.setLogicalStyle(style);
// Set paragraph style; removes logical style
style = textPane.addStyle(null, null);
StyleConstants.setUnderline(style, true);
textPane.setParagraphAttributes(style, true);
// paragraph is now underlined, not red
}
}
|