?? editormessage.java~1~
字號:
package chat;import java.awt.*;import javax.swing.*;import javax.swing.text.*;//import javax.swing.event.*;import java.awt.event.*;import javax.swing.text.html.*;public class EditorMessage extends JPanel implements ActionListener { Font font; JPanel toolPanel; JPanel messagePanel; JTextPane messageTextPane; JScrollPane messageScrollPane; JComboBox fontFamilyCB; JButton boldButton; JButton italicButton; JButton underLineButton; static String fontFamily; public EditorMessage() { try { jbInit(); } catch(Exception ex) { ex.printStackTrace(); } } void jbInit() throws Exception { font=new Font("新宋體",Font.PLAIN,12); toolPanel=new JPanel(); messagePanel=new JPanel(); messageTextPane=new JTextPane(); messageTextPane.setContentType("text/html"); messageScrollPane=new JScrollPane(messageTextPane); messageScrollPane.setPreferredSize(new Dimension(400,400)); fontFamilyCB=new JComboBox(GraphicsEnvironment.getLocalGraphicsEnvironment(). getAvailableFontFamilyNames()); fontFamilyCB.setFont(font); fontFamilyCB.setBackground(Color.white); fontFamilyCB.addActionListener(this); boldButton=new JButton(); italicButton=new JButton(); underLineButton=new JButton(); //boldButton.setAction(getComponent().getActionMap().get("font-bold")); italicButton.setAction(getComponent().getActionMap().get("font-italic")); underLineButton.setAction(getComponent().getActionMap().get("font-underline")); boldButton.setAction(new StyledEditorKit.FontFamilyAction(fontFamily,fontFamily)); toolPanel.add(fontFamilyCB); toolPanel.add(boldButton); toolPanel.add(italicButton); toolPanel.add(underLineButton); messagePanel.add(messageScrollPane); this.setLayout(new GridLayout(2,1)); this.add(toolPanel); this.add(messagePanel); } public void actionPerformed(ActionEvent evt) { JComboBox source = (JComboBox) evt.getSource(); fontFamily = (String) source.getSelectedItem(); fontFamilyCB.setAction(new StyledEditorKit.FontFamilyAction(fontFamily,fontFamily)); //getComponent().repaint(); // JEditorPane editorPane=(JEditorPane)getComponent(); // HTMLEditorKit kit = (HTMLEditorKit)editorPane.getEditorKit(); //HTMLDocument doc = (HTMLDocument)getComponent().getDocument(); // SimpleAttributeSet as = new SimpleAttributeSet();// StyleConstants.setFontFamily(fontFamily); //as.addAttribute("fontfamily",fontFamily); // setCharacterAttributes(editorPane, as, false);// getComponent().ABORT System.out.println(fontFamily); //fontLabel.setFont(new Font(item, Font.PLAIN, 12)); } public JTextComponent getComponent(){ return this.messageTextPane; } protected void makeAction(){ Action a; a=getComponent().getActionMap().get("font-bold"); a=getComponent().getActionMap().get("font-italic"); a=getComponent().getActionMap().get("font-underLine"); } public static void main(String[] args){ JFrame frame=new JFrame(); EditorMessage editorMessage=new EditorMessage(); frame.getContentPane().add(editorMessage); frame.setVisible(true); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -