Java JTextPane setSelectionForeground(JTextPane textPane, Color color)

Here you can find the source of setSelectionForeground(JTextPane textPane, Color color)

Description

Sets the foreground color of the selection.

License

Apache License

Declaration

public static void setSelectionForeground(JTextPane textPane,
        Color color) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.awt.Color;

import javax.swing.JTextPane;

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

public class Main {
    /**/*from w w  w. j  av a  2 s  .  c  om*/
     * Sets the foreground color of the selection.
     */
    public static void setSelectionForeground(JTextPane textPane,
            Color color) {
        if (color != null) {
            String FOREGROUND = "foregroundColor." + color.toString();
            Style foregroundStyle = new StyleContext().addStyle(FOREGROUND,
                    null);
            foregroundStyle.addAttribute(StyleConstants.Foreground, color);
            textPane.setCharacterAttributes(foregroundStyle, false);
        }
    }
}

Related

  1. saveFile(JTextPane txt)
  2. scrollTo(JTextPane textPane, int position)
  3. setDefaultTextPaneProperties(JTextPane textPane)
  4. setJTextPaneFont(JTextPane jtp, Font font, Color c)
  5. setSelectionFontSize(JTextPane textPane, int fontSize)
  6. setStyle(JTextPane textPane, int start, int length, String name)
  7. setStyle(JTextPane textPane, Style style)
  8. setTabs(int charactersPerTab, JTextPane textpane)
  9. setTextToPane(JTextPane textPane, String text, Color foregroundColor, Color backgroundColor)