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

📄 simpletextpanel.java

📁 piweurrrrq i o fhsadhfka fd dskajc zxkjcnkjsahc
💻 JAVA
字号:
package com.lyrisoft.chat.client.gui.jfc;import java.awt.Color;import javax.swing.*;import javax.swing.text.*;import javax.swing.text.html.*;import com.lyrisoft.chat.client.gui.IMessageWindow;public class SimpleTextPanel extends JPanel implements IMessageWindow {    private JTextPane _textArea;    private Position _endPosition;    private SimpleAttributeSet _userAttributes;    private SimpleAttributeSet _normalAttributes;    private SimpleAttributeSet _privateAttributes;    private SimpleAttributeSet _privateTextAttributes;    private SimpleAttributeSet _errorAttributes;    public SimpleTextPanel() {        _textArea = new JTextPane();        _textArea.setEditable(false);        setLayout(new java.awt.GridLayout());                JScrollPane scroller = new JScrollPane(_textArea,                                                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,                                               ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);        add(scroller);        Document doc = _textArea.getStyledDocument();        _endPosition = doc.getEndPosition();        AttributeSet baseAttributes = doc.getDefaultRootElement().getAttributes();        _normalAttributes = new SimpleAttributeSet(baseAttributes);        _normalAttributes.addAttribute(StyleConstants.Foreground, Color.black);        _normalAttributes.addAttribute(StyleConstants.FontFamily, "SansSerif");        _userAttributes = new SimpleAttributeSet(_normalAttributes);        _userAttributes.addAttribute(StyleConstants.Foreground, Color.blue);        _errorAttributes = new SimpleAttributeSet(_normalAttributes);        _errorAttributes.addAttribute(StyleConstants.Foreground, Color.red);        _errorAttributes.addAttribute(StyleConstants.Bold, new Boolean(true));        _privateAttributes = new SimpleAttributeSet(_normalAttributes);        _privateAttributes.addAttribute(StyleConstants.Foreground, Color.red);        _privateTextAttributes = new SimpleAttributeSet(_normalAttributes);        _privateTextAttributes.addAttribute(StyleConstants.Foreground, Color.black);        _privateTextAttributes.addAttribute(StyleConstants.Italic, new Boolean(true));    }    public void displayPrivateMessage(String user, String message) {        append(user, _userAttributes);        append(" (privately)", _privateAttributes);        append(": " + message + "\n", _privateTextAttributes);    }    public void displayPrivateEmote(String user, String message) {        append("(privately) ", _privateAttributes);        append(user, _userAttributes);        append(" " + message + "\n", _privateTextAttributes);    }    public void displayMessage(String user, String message) {        append(user, _userAttributes);        append(": " + message + "\n", _normalAttributes);    }        public void displayMessage(String message) {        append(message + "\n", _normalAttributes);    }    public void displayError(String error) {        append(error + "\n", _errorAttributes);    }    void append(String text, AttributeSet attributes) {         Document doc = _textArea.getDocument();        try {            doc.insertString(_endPosition.getOffset()-1, text, attributes);            _textArea.setCaretPosition(_endPosition.getOffset()-1);        }        catch (BadLocationException e) {            throw new RuntimeException(e.toString());        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -