Example usage for javax.swing.text StyledEditorKit.FontFamilyAction StyledEditorKit.FontFamilyAction

List of usage examples for javax.swing.text StyledEditorKit.FontFamilyAction StyledEditorKit.FontFamilyAction

Introduction

In this page you can find the example usage for javax.swing.text StyledEditorKit.FontFamilyAction StyledEditorKit.FontFamilyAction.

Prototype

public FontFamilyAction(String nm, String family) 

Source Link

Document

Creates a new FontFamilyAction.

Usage

From source file:components.TextComponentDemo.java

protected JMenu createStyleMenu() {
    JMenu menu = new JMenu("Style");

    Action action = new StyledEditorKit.BoldAction();
    action.putValue(Action.NAME, "Bold");
    menu.add(action);/*from   ww w  . j av  a2 s.c  o  m*/

    action = new StyledEditorKit.ItalicAction();
    action.putValue(Action.NAME, "Italic");
    menu.add(action);

    action = new StyledEditorKit.UnderlineAction();
    action.putValue(Action.NAME, "Underline");
    menu.add(action);

    menu.addSeparator();

    menu.add(new StyledEditorKit.FontSizeAction("12", 12));
    menu.add(new StyledEditorKit.FontSizeAction("14", 14));
    menu.add(new StyledEditorKit.FontSizeAction("18", 18));

    menu.addSeparator();

    menu.add(new StyledEditorKit.FontFamilyAction("Serif", "Serif"));
    menu.add(new StyledEditorKit.FontFamilyAction("SansSerif", "SansSerif"));

    menu.addSeparator();

    menu.add(new StyledEditorKit.ForegroundAction("Red", Color.red));
    menu.add(new StyledEditorKit.ForegroundAction("Green", Color.green));
    menu.add(new StyledEditorKit.ForegroundAction("Blue", Color.blue));
    menu.add(new StyledEditorKit.ForegroundAction("Black", Color.black));

    return menu;
}

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatWritePanel.java

/**
 * Sets the font family and size/*from  w  w w  .j a  v a  2 s  .  c o  m*/
 * @param family the family name
 * @param size the size
 */
public void setFontFamilyAndSize(String family, int size) {
    // Family
    ActionEvent evt = new ActionEvent(editorPane, ActionEvent.ACTION_PERFORMED, family);

    Action action = new StyledEditorKit.FontFamilyAction(family, family);
    action.actionPerformed(evt);

    // Size
    evt = new ActionEvent(editorPane, ActionEvent.ACTION_PERFORMED, Integer.toString(size));
    action = new StyledEditorKit.FontSizeAction(Integer.toString(size), size);
    action.actionPerformed(evt);
}