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

📄 styles.java

📁 1. 消息即时通信 2. 消息发送实现一对一、一对多等多种发送模式 3. 发送的消息实现多彩文本编辑
💻 JAVA
字号:
package chat;
import java.awt.*;
import javax.swing.*;
import javax.swing.text.*;
public class Styles {
  public static void addStylesToDocument(StyledDocument doc){
    //JButton jbutton;
    //jbutton=jpanel;
    Style def=StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

    Style regular = doc.addStyle("regular", def);
    StyleConstants.setFontFamily(def, "SansSerif");

    Style myStyle=doc.addStyle("italic", regular);
    StyleConstants.setItalic(myStyle,true);

    myStyle=doc.addStyle("bold",regular);
    StyleConstants.setBold(myStyle,true);
  }

  public static void addStylesToDocument(StyledDocument doc,JPanel jpanel){
    //JButton jbutton;
    //jbutton=jpanel;
    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.
        DEFAULT_STYLE);

    Style regular = doc.addStyle("regular", def);
    StyleConstants.setFontFamily(def, "SansSerif");

    Style myStyle = doc.addStyle("italic", regular);
    StyleConstants.setItalic(myStyle, true);

    myStyle = doc.addStyle("bold", regular);
    StyleConstants.setBold(myStyle, true);

    myStyle = doc.addStyle("jpanel", def);
    StyleConstants.setComponent(myStyle, jpanel);
  }

  public static void addStylesToDocument(StyledDocument doc,Font font){
    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.
        DEFAULT_STYLE);

    Style myStyle=doc.addStyle("newStyle",def);

    StyleConstants.setFontFamily(myStyle,font.getName());
    StyleConstants.setFontSize(myStyle,font.getSize());
    switch(font.getStyle()){
      case 0:
        break;
      case 1:
        StyleConstants.setBold(myStyle,true);
        break;
      case 2:
        StyleConstants.setItalic(myStyle,true);
        break;
      case 3:
        StyleConstants.setBold(myStyle,true);
        StyleConstants.setItalic(myStyle,true);
        break;
    }
  }
  public static void addStylesToDocument(StyledDocument doc,Font font,Color color,boolean
         underLine,boolean strikeThrough,boolean superscript,boolean subscript){
    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.
        DEFAULT_STYLE);
    Style myStyle=doc.addStyle("newStyle",def);
    StyleConstants.setFontFamily(myStyle,font.getName());
    StyleConstants.setFontSize(myStyle,font.getSize());
    switch(font.getStyle()){
      case 0:
        break;
      case 1:
        StyleConstants.setBold(myStyle,true);
        break;
      case 2:
        StyleConstants.setItalic(myStyle,true);
        break;
      case 3:
        StyleConstants.setBold(myStyle,true);
        StyleConstants.setItalic(myStyle,true);
        break;
    }
    StyleConstants.setForeground(myStyle,color);
    if(underLine){
      StyleConstants.setUnderline(myStyle,true);
    }else{
      StyleConstants.setUnderline(myStyle,false);
    }
    if(strikeThrough){
      StyleConstants.setStrikeThrough(myStyle,true);
    }else{
      StyleConstants.setStrikeThrough(myStyle,false);
    }
    if(superscript){
      StyleConstants.setSuperscript(myStyle,true);
    }else{
      StyleConstants.setSuperscript(myStyle,false);
    }
    if(subscript){
      StyleConstants.setSubscript(myStyle,true);
    }else{
      StyleConstants.setSubscript(myStyle,false);
    }
  }





}










⌨️ 快捷键说明

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