1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
Style defaut = jTextPane1.getStyle("default");
Style style1 = jTextPane1.addStyle("style1", defaut);
StyleConstants.setFontFamily(style1, "Comic sans MS");
StyleConstants.setFontSize(style1, 14);
StyleConstants.setForeground(style1, Color.BLUE);
Style style2 = jTextPane1.addStyle("style2", style1);
StyleConstants.setForeground(style2, Color.RED);
StyleConstants.setFontSize(style2, 25);
String s1 = "Bonjour\r\n";
String s2 = "Bonjour\r\n";
String s3 = "Bonjour\r\n";
StyledDocument sDoc = (StyledDocument) jTextPane1.getDocument();
try {
int pos = 0;
sDoc.insertString(pos, s1, defaut);
pos += s1.length();
sDoc.insertString(pos, s2, style1);
pos += s2.length();
sDoc.insertString(pos, s3, style2);
} catch (BadLocationException e) {
//
} |
Partager