📄 font.java
字号:
/* * font.java * * Created on 2005年11月21日, 下午8:07 */package examples.mynote;/** * * @author leafyoung */import java.awt.*;import javax.swing.*;import java.awt.event.*;import javax.swing.event.*;import javax.swing.text.*;public class font extends JFrame implements ActionListener{ String font=null; String fontarr[]={"宋体","隶书","TimesRoman","Forte"}; JList lis=new JList(fontarr); JLabel lb=new JLabel(); JButton OK=new JButton("确定"); MutableAttributeSet normal; JTextPane temp=new JTextPane(); /////////////////////////////////////////// public font(JTextPane textPane) { Container cp=getContentPane(); cp.setLayout(new BorderLayout()); lis.setVisibleRowCount(3); lis.setBorder(BorderFactory.createTitledBorder("请选择字体")); cp.add(lb,BorderLayout.NORTH); cp.add(new JScrollPane(lis),BorderLayout.CENTER); cp.add(OK,BorderLayout.SOUTH); setSize(200,300); setLocation(500,300); temp=textPane; OK.addActionListener(this); } ////////////////////////////////////////////////////////////// public void actionPerformed(ActionEvent e) { Object eventSource=e.getSource(); if(eventSource==OK) { int index=lis.getSelectedIndex(); font=fontarr[index]; } normal = new SimpleAttributeSet(); //字体设置 StyleConstants.setFontFamily(normal, font); temp.setCharacterAttributes(normal,false); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -