styles.java~21~

来自「1. 消息即时通信 2. 消息发送实现一对一、一对多等多种发送模式 3. 发」· JAVA~21~ 代码 · 共 117 行

JAVA~21~
117
字号
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,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;
    }
    if(underLine){
      StyleConstants.setUnderline(myStyle,true);
      System.out.println("underlie");
    }
    if(strikeThrough){
      StyleConstants.setStrikeThrough(myStyle,true);
      System.out.println("underlie");
    }
    if(superscript){
      StyleConstants.setSuperscript(myStyle,true);
      System.out.println("underlie");
    }
    if(subscript){
      StyleConstants.setSubscript(myStyle,true);
      System.out.println("underlie");
    }
  }





}










⌨️ 快捷键说明

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