📄 documentdemo.java
字号:
package chapter14;
import java.awt.Color;
import java.awt.Component;
import javax.swing.JFrame;
import javax.swing.JTextPane;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
public class Documentdemo{
private JTextPane text;
public Documentdemo(){
text=new JTextPane();
text.setBackground(Color.black);
text.setEditable(true);
}
public void setyellowbold20(String str){
SimpleAttributeSet attreset=new SimpleAttributeSet();
StyleConstants.setForeground(attreset,Color.yellow);
StyleConstants.setBold(attreset,false);
StyleConstants.setFontSize(attreset, 20);
insert(str,attreset);
}
public void insert(String str,AttributeSet attreset){
Document docs=text.getDocument();
str=str+"\n";
try{
docs.insertString(docs.getLength(), str, attreset);
}catch(BadLocationException e){
e.printStackTrace();
}
}
public Component getcomponent(){
return text;
}
public static void main(String[] args) {
Documentdemo pane=new Documentdemo();
pane.setyellowbold20("wo shi chenbiao");
JFrame frame=new JFrame();
frame.getContentPane().add(pane.getcomponent());
frame.pack();
frame.show();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -