⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editormessage.java~1~

📁 1. 消息即时通信 2. 消息发送实现一对一、一对多等多种发送模式 3. 发送的消息实现多彩文本编辑
💻 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 + -