[摘要]Font 菜单项开始,该菜单将引出一个FontChooser (字型选择)对话框。 给FontChooser附加一个菜单项事件(源程序)如下: void jMenuItem5_actionP...
Font 菜单项开始,该菜单将引出一个FontChooser (字型选择)对话框。
给FontChooser附加一个菜单项事件(源程序)如下:
void jMenuItem5_actionPerformed(ActionEvent e) {
// Handle the "Edit Font" menu item
// Pick up the existing font from the text area
// and put it into the FontChooser before showing
// the FontChooser, so that we are editing the
// existing / previous font.
fontChooser1.setSelectedFont(jTextArea1.getFont());
// Obtain the new Font from the FontChooser.
// First test the return value of showDialog() to
// see if the user pressed OK.
if (fontChooser1.showDialog()) {
// Set the font of jTextArea1 to the font
// the user selected before pressing the OK button
jTextArea1.setFont(fontChooser1.getSelectedFont());
}
//repaints menu after item is selected
this.repaint();
//Repaints text properly if some text is highlighted when font is changed.
jTextArea1.repaint();
}
给JcolorChooser(颜色选择)附加一个菜单项事件
创建Edit
关键词:JBuilder 9 开发一个文本编辑器