aset=sc.addAttribute(aset, StyleConstants.FontSize, 30);
int start= editorPane.getSelectionStart();
int end=editorPane.getSelectionEnd();
String str= document.getText(start,end-start);
document.remove(start, end-start);
document.insertString(start, str, aset);
} catch (BadLocationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
menuFile.add(itemColor);
itemColor.setMnemonic('C');
//设置快捷键
itemColor.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.ALT_MASK));
this.add(editorPane);
editorPane.setText("测试");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/**
* @param args
*/
public static void main(String[] args) {
MainFrame mainFrame=new MainFrame();
mainFrame.setSize(400, 300);
mainFrame.setVisible(true);
}
}
摘自 zyqyz520的专栏