font.java

来自「一个java记事本程序 包括新建」· Java 代码 · 共 65 行

JAVA
65
字号
/* * 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 + =
减小字号Ctrl + -
显示快捷键?