create Swing Text Style - Java Swing

Java examples for Swing:JTextComponent

Description

create Swing Text Style

Demo Code


//package com.java2s;
import java.awt.Color;

import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;

public class Main {
    public static void createStyle(StyleContext sc, String aName,
            Color aForegroundColor, String aFontFamily,
            Color aBackgroundColor, int aFontSize, Boolean isBold) {
        Style cursorStyle = sc.addStyle(aName, null);
        StyleConstants.setForeground(cursorStyle, aForegroundColor);
        StyleConstants.setFontFamily(cursorStyle, aFontFamily);
        StyleConstants.setBackground(cursorStyle, aBackgroundColor);
        StyleConstants.setFontSize(cursorStyle, aFontSize);
        if (isBold != null)
            StyleConstants.setBold(cursorStyle, isBold);
    }/*from w w w .  j  a v  a  2  s.c  o  m*/
}

Related Tutorials