文档库

最新最全的文档下载
当前位置:文档库 > java记事本源码

java记事本源码

package com.java.notepad;

import javax.swing.*;

import javax.swing.border.Border;

import javax.swing.event.MenuEvent;

import javax.swing.event.MenuListener;

import javax.swing.event.UndoableEditEvent;

import javax.swing.event.UndoableEditListener;

import javax.swing.filechooser.FileFilter;

import java.awt.*;

import java.awt.datatransfer.Clipboard;

import java.awt.datatransfer.DataFlavor;

import java.awt.datatransfer.Transferable;

import java.awt.event.*;

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

import java.util.Vector;

import javax.swing.JDialog;

import javax.swing.undo.UndoManager;

/**

* 记事本

* @author WMeng

* @version 1.0 2012.08.15

*

*/

public class NotePad {

public static void main(String[] args)

{

NotePadFrame frame=new NotePadFrame();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

//frame.textArea.requestFocus();

frame.textArea.requestFocusInWindow();

}

}

class NotePadFrame extends JFrame {

public NotePadFrame()

{

init();

}

public NotePadFrame(int x,int y)

{

this.setLocation(x,y);

init();

}

JTextArea textArea=new JTextArea(15,50);

JScrollPane scrollPane;

JPopupMenu popupmenu;

boolean isSave=false;

private void init()

{

final UndoManager manager = new UndoManager();

textArea.getDocument().addUndoableEditListener(new UndoableEditListener() {

public void undoableEditHappened(UndoableEditEvent e) {

manager.addEdit(e.getEdit());

}

});

//设置窗体观感

String plaf="com.sun.java.swing.plaf.windows.WindowsLookAndFeel";

try {

UIManager.setLookAndFeel(plaf);

SwingUtilities.updateComponentTreeUI(this);

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (InstantiationException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IllegalAccessException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (UnsupportedLookAndFeelException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

// UIManager.LookAndFeelInfo[] infos=UIManager.getInstalledLookAndFeels(); // for(UIManager.LookAndFeelInfo i:infos)

// System.out.println(i);

//获取计算机平铺宽度、高度

int screenWidth=Toolkit.getDefaultToolkit().getScreenSize().width;

int screenHeight=Toolkit.getDefaultToolkit().getScreenSize().height;

Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(this.getGraphicsConfiguration());

//不管任务栏移动桌面什么位置,都可以返回所需要的窗口,也就得到了所需要窗口方形

int width=screenInsets.right;

int height=screenInsets.bottom;

Image img=Toolkit.getDefaultToolkit().getImage("image/title.png");

this.setIconImage(img);

this.setTitle("记事本");

this.setSize((screenWidth-width)/2,(screenHeight-height)/2);

this.setLocation(500,200);

x=this.getX();

y=this.getY();

textArea.setLineWrap(true);//激活自动换行功能

textArea.setWrapStyleWord(true);//激活断行不断字功能

/**

* 工具栏

*/

JToolBar toolBar=new JToolBar();

JButton xin=new JButton();

xin.setIcon(new ImageIcon("image/toolbar/newFile.png"));

xin.setToolTipText("新建");

xin.addActionListener(new ActionListener() { //定义"新建"组件操作

@Override

public void actionPerformed(ActionEvent arg0) {

System.out.println("ok");

NotePadFrame f=new NotePadFrame(x+20,y+20);

f.setVisible(true);

}

});

JButton open=new JButton();

open.setIcon(new ImageIcon("image/toolbar/openFile.png"));

open.setToolTipText("打开");

open.addActionListener(new ActionListener() { //定义"打开"组件操作

@Override

public void actionPerformed(ActionEvent arg0) {

chooseToOpen();

}

});

JButton saveFile=new JButton();

saveFile.setIcon(new ImageIcon("image/toolbar/saveFile.png")); saveFile.setToolTipText("保存");

saveFile.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

chooseToSave();

}

});

JButton copy=new JButton();

copy.setIcon(new ImageIcon("image/toolbar/copy.png")); copy.setToolTipText("复制");

copy.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

textArea.copy();

textArea.requestFocusInWindow();

}

});

JButton cut=new JButton();

cut.setIcon(new ImageIcon("image/toolbar/cut.png"));

cut.setToolTipText("剪切");

cut.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

textArea.cut();

textArea.requestFocusInWindow();

}

});

JButton paste=new JButton();

paste.setIcon(new ImageIcon("image/toolbar/paste.png")); paste.setToolTipText("粘贴");

paste.setEnabled(isClipboardString());

paste.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

textArea.paste();

textArea.requestFocusInWindow();

}

});

JButton undo=new JButton();

undo.setIcon(new ImageIcon("image/toolbar/undo.png")); undo.setToolTipText("撤销");

undo.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

if(manager.canUndo())

{

manager.undo();

textArea.requestFocusInWindow();

}else JOptionPane.showOptionDialog(null,

"没有可撤销的内容",

"错误",

JOptionPane.DEFAULT_OPTION,

http://www.wendangku.net/doc/ae649b1114791711cc791778.htmlRMA TION_MESSAGE,

null, null, null);

textArea.requestFocusInWindow();

}

});

JButton redo=new JButton();

redo.setIcon(new ImageIcon("image/toolbar/redo.png"));

redo.setToolTipText("重复");

redo.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

if(manager.canRedo())

{

manager.redo();

textArea.requestFocusInWindow();

}else JOptionPane.showOptionDialog(null,

"没有可重复的内容",

"错误",

JOptionPane.DEFAULT_OPTION,

http://www.wendangku.net/doc/ae649b1114791711cc791778.htmlRMA TION_MESSAGE,

null, null, null);

textArea.requestFocusInWindow();

}

});

//JLabel findLabel=new JLabel("查找");

JTextField findTextField=new JTextField();

JButton findButton=new JButton("查找");

findButton.setIcon(new ImageIcon("image/toolbar/find.png")); toolBar.add(xin);

toolBar.add(open);

toolBar.add(saveFile);

toolBar.addSeparator();

toolBar.add(copy);

toolBar.add(cut);

toolBar.add(paste);

toolBar.addSeparator();

toolBar.add(undo);

toolBar.add(redo);

toolBar.addSeparator();

//toolBar.add(findLabel);

toolBar.add(findTextField);

toolBar.add(findButton);

this.add(toolBar,BorderLayout.NORTH);

/**

* 菜单栏

*/

JMenuBar menuBar=new JMenuBar();

this.setJMenuBar(menuBar);

JMenu file=new JMenu("文件(F)");

file.setMnemonic('F');

JMenuItem newMenuItem=new JMenuItem("新建(N)",'N');

newMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK));

newMenuItem.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent arg0){

System.out.println("ok");

new NotePadFrame();

}

});

JMenuItem openMenuItem=new JMenuItem("打开(O)",'O');

openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK));

openMenuItem.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

chooseToOpen();

}

});

final JMenuItem save=new JMenuItem("保存(S)",'S');

save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));

save.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

chooseToSave();

}

});

JMenuItem saveAs=new JMenuItem("另存为");

saveAs.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e)

{

chooseToSave();

}

});

JMenuItem exit=new JMenuItem("退出");

exit.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e)

{

System.exit(0);

}

});

file.add(newMenuItem);

file.add(openMenuItem);

file.add(save);

file.add(saveAs);

file.addSeparator();

file.add(exit);

file.addMenuListener(new MenuListener(){

@Override

public void menuCanceled(MenuEvent e) {

// TODO Auto-generated method stub }

@Override

public void menuDeselected(MenuEvent e) { // TODO Auto-generated method stub

}

@Override

public void menuSelected(MenuEvent e) {

// TODO Auto-generated method stub

if(isSave==true)save.setEnabled(false);

}

});

JMenu edit=new JMenu("编辑(E)");

edit.setMnemonic('E');

final JMenuItem undoMenuItem=new JMenuItem("撤销(Z)",'Z');

undoMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_MASK));

undoMenuItem.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

manager.undo();

}

});

final JMenuItem redoMenuItem=new JMenuItem("重复(Y)",'Y');

redoMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.CTRL_MASK));

redoMenuItem.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

manager.redo();

}

});

final JMenuItem cutMenuItem=new JMenuItem("剪切(X)",'X');

cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));

cutMenuItem.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

textArea.cut();

}

});

final JMenuItem copyMenuItem=new JMenuItem("复制(C)",'C');

copyMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK));

copyMenuItem.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

textArea.copy();

}

});

final JMenuItem pasteMenuItem=new JMenuItem("粘贴(P)",'P');

pasteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK));

pasteMenuItem.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

textArea.paste();

}

});

JMenuItem findMenuItem=new JMenuItem("查找/替换(F)…",'F');

findMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK));

findMenuItem.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

}

});

JMenuItem findNextMenuItem=new JMenuItem("查找下一个(K)",'K');

findNextMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_K, InputEvent.CTRL_MASK));

findNextMenuItem.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

}

});

JMenuItem selevtAllMenuItem=new JMenuItem("全选(A)",'A');

selevtAllMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK));

selevtAllMenuItem.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

textArea.selectAll();

}

});

edit.add(undoMenuItem);

edit.add(redoMenuItem);

edit.addSeparator();

edit.add(copyMenuItem);

edit.add(cutMenuItem);

edit.add(pasteMenuItem);

edit.addSeparator();

edit.add(findMenuItem);

edit.add(findNextMenuItem);

edit.add(selevtAllMenuItem);

edit.addMenuListener(new MenuListener(){

@Override

public void menuCanceled(MenuEvent arg0) {

// TODO Auto-generated method stub

}

@Override

public void menuDeselected(MenuEvent arg0) {

// TODO Auto-generated method stub

}

@Override

public void menuSelected(MenuEvent arg0) {

// TODO Auto-generated method stub

cutMenuItem.setEnabled(isCanCopy());

copyMenuItem.setEnabled(isCanCopy());

pasteMenuItem.setEnabled(isClipboardString());

undoMenuItem.setEnabled(manager.canUndo());

redoMenuItem.setEnabled(manager.canRedo());

}

});

JMenu format=new JMenu("格式(O)");

format.setMnemonic('O');

final JCheckBoxMenuItem autoWrap=new JCheckBoxMenuItem("自动换行");

autoWrap.setSelected(true);

autoWrap.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

if(autoWrap.isSelected())

{

textArea.setLineWrap(true);//激活自动换行功能

textArea.setWrapStyleWord(true);//激活断行不断字功能

}else

{

textArea.setLineWrap(false);//激活自动换行功能

textArea.setWrapStyleWord(false);//激活断行不断字功能}

}

});

JMenuItem font=new JMenuItem("字体(F)…",'F');

font.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

fontSet();

}

});

JMenuItem bgColor=new JMenuItem("背景色(C)…",'C');

bgColor.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

final JColorChooser bcolor=new JColorChooser();

JDialog dialog=JColorChooser.createDialog(textArea, "背景色设置",false,bcolor, new ActionListener(){

public void actionPerformed(ActionEvent e)

{

textArea.setBackground(bcolor.getColor());

}

},null);

dialog.setResizable(false);

dialog.setVisible(true);

}

});

JMenuItem fgColor=new JMenuItem("前景色(K)…",'K');

fgColor.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

final JColorChooser bcolor=new JColorChooser();

JDialog dialog=JColorChooser.createDialog(textArea, "前景色设置",false,bcolor, new ActionListener(){

public void actionPerformed(ActionEvent e)

{

textArea.setForeground(bcolor.getColor());

}

},null);

dialog.setResizable(false);

dialog.setVisible(true);

}

});

format.add(autoWrap);

format.add(font);

format.addSeparator();

format.add(bgColor);

format.add(fgColor);

JMenu findlook=new JMenu("查看(V)");

findlook.setMnemonic('V');

JCheckBoxMenuItem status=new JCheckBoxMenuItem("状态栏");

JMenuItem wordNumber=new JMenuItem("总字数…");

wordNumber.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

JDialog wordNumberDialog=new JDialog();

wordNumberDialog.setTitle("总字数");

JLabel words=new JLabel();

JLabel lines=new JLabel();

JPanel panel=new JPanel();

words.setText("共有"+textArea.getText().length()+"字");

lines.setText("共"+textArea.getLineCount()+"行");

panel.add(words);

panel.add(lines);

wordNumberDialog.add(panel);

System.out.println(textArea.getText().length());

wordNumberDialog.setSize(200,80);

wordNumberDialog.setLocation(x+200,y+200);

wordNumberDialog.setVisible(true);

}

});

findlook.add(status);

findlook.add(wordNumber);

JMenu help=new JMenu("帮助(H)");

help.setMnemonic('H');

JMenuItem about=new JMenuItem("关于记事本…");

about.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

// 显示对话框

JOptionPane.showOptionDialog(null,

" NotePad++ v1.0\n" +

" 程序设计:王盟盟\n" +

" 简介:\n " +

" 一个简单的文字编辑器\n" +

" 可作为验收Java的实现对象\n" +

" 欢迎网友下载研究交流\n\n" +

" ",

"NotePad",

JOptionPane.DEFAULT_OPTION,

http://www.wendangku.net/doc/ae649b1114791711cc791778.htmlRMA TION_MESSAGE,

null, null, null);

}

});

help.add(about);

menuBar.add(file);

menuBar.add(edit);

menuBar.add(format);

menuBar.add(findlook);

menuBar.add(help);

/**

* 弹出菜单

*/

popupmenu=new JPopupMenu();

final JMenuItem undoPopupItem=new JMenuItem("撤销(Z)",'Z');

undoPopupItem.setAccelerator(KeyStroke.getKeyStroke("ctrl z"));

undoPopupItem.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

manager.undo();

}

});

final JMenuItem redoPopupItem=new JMenuItem("重复(Y)",'Y');

redoPopupItem.setAccelerator(KeyStroke.getKeyStroke("ctrl y"));

redoPopupItem.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

manager.redo();

}

});

final JMenuItem cutPopupItem=new JMenuItem("剪切(X)",'X');

cutPopupItem.setAccelerator(KeyStroke.getKeyStroke("ctrl x"));

if(isCanCopy()==false)cutPopupItem.setEnabled(false);

cutPopupItem.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

textArea.cut();

}

});

final JMenuItem copyPopupItem=new JMenuItem("复制(C)",'C');

copyPopupItem.setAccelerator(KeyStroke.getKeyStroke("ctrl c"));

copyPopupItem.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

textArea.copy();

}

});

JMenuItem pastePopupItem=new JMenuItem("粘贴(P)",'P'); pastePopupItem.setAccelerator(KeyStroke.getKeyStroke("ctrl v"));

if(isClipboardString()==false)pastePopupItem.setEnabled(false); pastePopupItem.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

textArea.paste();

}

});

JMenuItem findPopupItem=new JMenuItem("查找/替换(F)",'F'); findPopupItem.setAccelerator(KeyStroke.getKeyStroke("ctrl f")); findPopupItem.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

}

});

JMenuItem findNextPopupItem=new JMenuItem("查找下一个(K)",'K'); findNextPopupItem.setAccelerator(KeyStroke.getKeyStroke("ctrl k")); findNextPopupItem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e)

{

}

});

JMenuItem selevtAllPopupItem=new JMenuItem("全选(A)",'A'); selevtAllPopupItem.setAccelerator(KeyStroke.getKeyStroke("ctrl a")); selevtAllPopupItem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e)

{

textArea.selectAll();

}

});

popupmenu.add(undoPopupItem);

popupmenu.add(redoPopupItem);

popupmenu.addSeparator();

popupmenu.add(copyPopupItem);

popupmenu.add(cutPopupItem);

popupmenu.add(pastePopupItem);

popupmenu.addSeparator();

popupmenu.add(findPopupItem);

popupmenu.add(findNextPopupItem);

popupmenu.addSeparator();

popupmenu.add(selevtAllPopupItem);

textArea.setComponentPopupMenu(popupmenu);

textArea.addMouseListener(new MouseListener(){

@Override

public void mouseClicked(MouseEvent arg0) {

// TODO Auto-generated method stub

}

@Override

public void mouseEntered(MouseEvent arg0) {

// TODO Auto-generated method stub

}

@Override

public void mouseExited(MouseEvent arg0) {

// TODO Auto-generated method stub

}

@Override

public void mousePressed(MouseEvent arg0) {

// TODO Auto-generated method stub

if(arg0.getButton()==MouseEvent.BUTTON3)

{

copyPopupItem.setEnabled(isCanCopy());

cutPopupItem.setEnabled(isCanCopy());

undoPopupItem.setEnabled(manager.canUndo());

redoPopupItem.setEnabled(manager.canRedo());

popupmenu.show(textArea,arg0.getX(),arg0.getY());

}

}

@Override

public void mouseReleased(MouseEvent arg0) {

// TODO Auto-generated method stub

}

});

// textArea.setForeground(Color.RED);

// textArea.setBackground(Color.PINK);

textArea.setFont(new Font("宋体",Font.PLAIN,15));

scrollPane=new JScrollPane(textArea);

textArea.setComponentPopupMenu(popupmenu);

this.add(scrollPane);

//panel.setLayout(new GridBagLayout());

//this.add(panel)

}

private void fontSet()

{

//初始化字体对话框组件

final JDialog fontDialog=new JDialog(this);

fontDialog.setResizable(false);

fontDialog.setTitle("字体");

fontDialog.setSize(390,240);

fontDialog.setLocation(x+200,y+150);

JPanel border=new JPanel();

GridBagLayout layout=new GridBagLayout();

GridBagConstraints c=new GridBagConstraints();

fontDialog.setLayout(layout);

c.fill=GridBagConstraints.BOTH;

c.anchor=GridBagConstraints.NORTH;

c.insets=new Insets(0,5,0,0);

c.gridwidth=10;

c.gridheight=10;

c.ipadx=10;

// c.weightx=3;

// c.weighty=0;

JLabel fontName,fontSize,fontStyle;

final JList fontNameList ;

final JList fontSizeList ;

final JList fontStyleList;

final JTextField fontNameField;

JTextField fontSizeField;

final JTextField fontStyleField;

JButton confirm=new JButton("确定");

JButton cancle=new JButton("取消");

cancle.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

fontDialog.setVisible(false);

}

});

JLabel test=new JLabel();

/**

* 处理标签组件

*/

fontName=new JLabel(" 字体");

fontStyle=new JLabel(" 字形");

fontSize=new JLabel(" 大小");

c.gridx=0;

c.gridy=0;

c.gridwidth=1;

c.gridheight=1;

fontDialog.add(fontName,c);

c.gridx=1;

c.gridy=0;

c.gridwidth=1;

c.gridheight=1;

fontDialog.add(fontStyle,c);

c.gridx=2;

c.gridy=0;

c.gridwidth=1;

c.gridheight=1;

fontDialog.add(fontSize,c);

c.gridwidth = GridBagConstraints.REMAINDER; //end row

/**

* 处理文本域组件

*/

c.weightx=0;

c.weighty=0;

fontNameField=new JTextField();

fontStyleField=new JTextField(6);

fontSizeField=new JTextField();

c.gridx=0;

c.gridy=1;

c.gridwidth=1;

c.gridheight=1;

c.ipadx=10;

fontDialog.add(fontNameField,c);

c.gridx=1;

c.gridy=1;

fontDialog.add(fontStyleField,c);

c.gridx=2;

c.gridy=1;

c.gridwidth=1;

c.gridheight=1;

fontDialog.add(fontSizeField,c);

c.gridwidth = GridBagConstraints.REMAINDER; //end row

/**

* 处理列表组件

*/

Font font=new Font("宋体",Font.PLAIN,12);;

fontNameList=new JList();

action(fontNameList,fontNameField,test);

JScrollPane jsp1=new JScrollPane(fontNameList);

String[]

fontNames=GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyName s();

Vector vt=new Vector();

for(String name:fontNames)

{

vt.add(name);

}

fontNameList.setListData(vt);

fontNameList.setSelectedValue(textArea.getFont().getName(), true);

fontStyleList=new JList();

action(fontStyleList,fontStyleField,test);

JScrollPane jsp2=new JScrollPane(fontStyleList);

Vector vt1=new Vector();

vt1.add("常规");

vt1.add("粗体");

vt1.add("斜体");

vt1.add("粗斜体");

fontStyleList.setListData(vt1);

String fontStyleName=null;

if(textArea.getFont().isItalic()&&textArea.getFont().isBold())

fontStyleName="粗斜体";

else if(textArea.getFont().isItalic())

fontStyleName="斜体";

else if(textArea.getFont().isPlain())

fontStyleName="常规";

else if(textArea.getFont().isBold())

fontStyleName="粗体";

fontStyleList.setSelectedValue(fontStyleName,false); fontSizeList=new JList();

JScrollPane jsp3=new JScrollPane(fontSizeList); action(fontSizeList,fontSizeField,test);

Vector vt2=new Vector();

vt2.add(4);

vt2.add(5);

vt2.add(6);

vt2.add(7);

vt2.add(8);

vt2.add(9);

vt2.add(10);

vt2.add(11);

vt2.add(12);

vt2.add(13);

vt2.add(14);

vt2.add(15);

vt2.add(16);

vt2.add(18);

vt2.add(20);

vt2.add(22);

vt2.add(24);

vt2.add(26);

vt2.add(28);

vt2.add(30);

vt2.add(36);

vt2.add(42);

vt2.add(48);

vt2.add(50);

vt2.add(72);

vt2.add("初号");

vt2.add("小初");

vt2.add("一号");

vt2.add("小一");

vt2.add("二号");

vt2.add("小二");

vt2.add("三号");

vt2.add("小三");