📄 e989. inserting styled text in a jtextpane component.txt
字号:
See the StyleConstants class for more attributes.
try {
// Get the text pane's document
JTextPane textPane = new JTextPane();
StyledDocument doc = (StyledDocument)textPane.getDocument();
// Create a style object and then set the style attributes
Style style = doc.addStyle("StyleName", null);
// Italic
StyleConstants.setItalic(style, true);
// Bold
StyleConstants.setBold(style, true);
// Font family
StyleConstants.setFontFamily(style, "SansSerif");
// Font size
StyleConstants.setFontSize(style, 30);
// Background color
StyleConstants.setBackground(style, Color.blue);
// Foreground color
StyleConstants.setForeground(style, Color.white);
// Append to document
doc.insertString(doc.getLength(), "Some Text", style);
} catch (BadLocationException e) {
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -