Example usage for javax.swing.text StyleConstants setFontSize

List of usage examples for javax.swing.text StyleConstants setFontSize

Introduction

In this page you can find the example usage for javax.swing.text StyleConstants setFontSize.

Prototype

public static void setFontSize(MutableAttributeSet a, int s) 

Source Link

Document

Sets the font size attribute.

Usage

From source file:TextComponentDemo.java

protected SimpleAttributeSet[] initAttributes(int length) {
    // Hard-code some attributes.
    SimpleAttributeSet[] attrs = new SimpleAttributeSet[length];

    attrs[0] = new SimpleAttributeSet();
    StyleConstants.setFontFamily(attrs[0], "SansSerif");
    StyleConstants.setFontSize(attrs[0], 16);

    attrs[1] = new SimpleAttributeSet(attrs[0]);
    StyleConstants.setBold(attrs[1], true);

    attrs[2] = new SimpleAttributeSet(attrs[0]);
    StyleConstants.setItalic(attrs[2], true);

    attrs[3] = new SimpleAttributeSet(attrs[0]);
    StyleConstants.setFontSize(attrs[3], 20);

    attrs[4] = new SimpleAttributeSet(attrs[0]);
    StyleConstants.setFontSize(attrs[4], 12);

    attrs[5] = new SimpleAttributeSet(attrs[0]);
    StyleConstants.setForeground(attrs[5], Color.red);

    return attrs;
}

From source file:TextComponentDemo.java

protected SimpleAttributeSet[] initAttributes(int length) {
    //Hard-code some attributes.
    SimpleAttributeSet[] attrs = new SimpleAttributeSet[length];

    attrs[0] = new SimpleAttributeSet();
    StyleConstants.setFontFamily(attrs[0], "SansSerif");
    StyleConstants.setFontSize(attrs[0], 16);

    attrs[1] = new SimpleAttributeSet(attrs[0]);
    StyleConstants.setBold(attrs[1], true);

    attrs[2] = new SimpleAttributeSet(attrs[0]);
    StyleConstants.setItalic(attrs[2], true);

    attrs[3] = new SimpleAttributeSet(attrs[0]);
    StyleConstants.setFontSize(attrs[3], 20);

    attrs[4] = new SimpleAttributeSet(attrs[0]);
    StyleConstants.setFontSize(attrs[4], 12);

    attrs[5] = new SimpleAttributeSet(attrs[0]);
    StyleConstants.setForeground(attrs[5], Color.red);

    return attrs;
}

From source file:net.sf.jabref.gui.plaintextimport.TextInputDialog.java

private void addStylesToDocument() {
    //Initialize some styles.
    Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

    Style regularStyle = document.addStyle("regular", defaultStyle);
    StyleConstants.setFontFamily(defaultStyle, "SansSerif");
    StyleConstants.setFontSize(defaultStyle, Globals.prefs.getInt(JabRefPreferences.FONT_SIZE));

    Style s = document.addStyle("used", regularStyle);
    StyleConstants.setBold(s, true);
    StyleConstants.setForeground(s, Color.blue);

    s = document.addStyle("marked", regularStyle);
    StyleConstants.setBold(s, true);
    StyleConstants.setForeground(s, Color.red);
}

From source file:dylemator.DylematorUI.java

private void displayCenteredText(String text) {
    textArea.setText("");
    text = "\n\n\n" + text;
    SimpleAttributeSet attribs = new SimpleAttributeSet();
    if (sd == null)
        sd = new SettingsDialog(this, true);
    float fnt = sd.getFontSize();
    StyledDocument doc = (StyledDocument) textArea.getDocument();
    Style style = doc.getStyle(StyleContext.DEFAULT_STYLE);//doc.addStyle("MyStyle",null);
    StyleConstants.setFontSize(style, (int) fnt);
    StyleConstants.setLineSpacing(attribs, 0.5f);
    StyleConstants.setFontFamily(style, "Segoe UI");
    StyleConstants.setAlignment(attribs, StyleConstants.ALIGN_CENTER);
    textArea.setParagraphAttributes(attribs, true);

    try {/*from ww w. j av a 2  s.c om*/
        doc.insertString(doc.getLength(), text, style);
        doc.setParagraphAttributes(0, doc.getLength() - 1, attribs, false);
    } catch (BadLocationException ex) {
        Logger.getLogger(DylematorUI.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:ome.formats.importer.gui.GuiImporter.java

/**
 * This method appends data to the output window
 * /*from  ww  w  .j  ava 2 s.c  o m*/
 * @param s - text to append
 */
public void appendToOutput(String s) {
    try {
        StyledDocument doc = (StyledDocument) outputTextPane.getDocument();
        Style style = doc.addStyle("StyleName", null);
        StyleConstants.setForeground(style, Color.black);
        StyleConstants.setFontFamily(style, "SansSerif");
        StyleConstants.setFontSize(style, 12);
        StyleConstants.setBold(style, false);

        doc.insertString(doc.getLength(), s, style);

        //trim the document size so it doesn't grow to big
        int maxChars = 200000;
        if (doc.getLength() > maxChars)
            doc.remove(0, doc.getLength() - maxChars);

        //outputTextPane.setDocument(doc);
    } catch (BadLocationException e) {
    }
}

From source file:ome.formats.importer.gui.GuiImporter.java

/**
 * This method appends data to the output window.
 * //from  ww w.  ja  v a  2  s.c  o m
 * @param s - string to append
 */
public void appendToDebug(String s) {
    log.debug(s);
    try {
        StyledDocument doc = (StyledDocument) debugTextPane.getDocument();

        Style style = doc.addStyle("StyleName", null);
        StyleConstants.setForeground(style, Color.black);
        StyleConstants.setFontFamily(style, "SansSerif");
        StyleConstants.setFontSize(style, 12);
        StyleConstants.setBold(style, false);

        doc.insertString(doc.getLength(), s, style);

        //trim the document size so it doesn't grow to big
        int maxChars = 200000;
        if (doc.getLength() > maxChars)
            doc.remove(0, doc.getLength() - maxChars);

        //debugTextPane.setDocument(doc);
    } catch (BadLocationException e) {
    }
}

From source file:org.astrojournal.logging.JTextPaneAppender.java

/**
 * Add the graphical JTextPane to capture the logging information.
 * /*ww w.j av a  2  s .c  om*/
 * @param textPane
 */
public static void addJTextPane(final JTextPane textPane) {
    // The application graphical output
    jTextPane = textPane;

    // Define JTextPane styles
    StyledDocument doc = jTextPane.getStyledDocument();
    styleRegular = doc.addStyle("regular", null);
    StyleConstants.setForeground(styleRegular, Color.BLACK);
    StyleConstants.setFontSize(styleRegular, 12);
    StyleConstants.setFontFamily(styleRegular, "Arial");

    styleBold = doc.addStyle("bold", styleRegular);
    StyleConstants.setBold(styleBold, true);

    styleItalic = doc.addStyle("italic", styleRegular);
    StyleConstants.setItalic(styleItalic, true);

    styleSmall = doc.addStyle("small", styleRegular);
    StyleConstants.setFontSize(styleSmall, 11);

    styleSmallItalic = doc.addStyle("smallItalic", styleSmall);
    StyleConstants.setItalic(styleSmallItalic, true);

    styleRed = doc.addStyle("red", styleBold);
    StyleConstants.setForeground(styleRed, Color.RED);

    styleBlue = doc.addStyle("blue", styleSmall);
    StyleConstants.setForeground(styleBlue, Color.BLUE);

    // Remove the Appender Console as the GUI is being initialised and
    // therefore having this information twice is not desirable.
    Logger logger = LogManager.getLogger("Console");
    org.apache.logging.log4j.core.Logger coreLogger = (org.apache.logging.log4j.core.Logger) logger;
    LoggerContext context = coreLogger.getContext();
    coreLogger.removeAppender(context.getConfiguration().getAppender("Console"));
}

From source file:org.docx4all.ui.main.WordMLEditor.java

private JEditorPane createSourceView(WordMLTextPane editorView) {
    //Create the Source View
    JEditorPane sourceView = new JEditorPane();

    MutableAttributeSet attrs = new SimpleAttributeSet();
    StyleConstants.setFontFamily(attrs, FontManager.getInstance().getSourceViewFontFamilyName());
    StyleConstants.setFontSize(attrs, FontManager.getInstance().getSourceViewFontSize());

    // TODO - only do this if the font is available.
    Font font = new Font("Arial Unicode MS", Font.PLAIN, 12);

    System.out.println(font.getFamily());
    System.out.println(font.getFontName());
    System.out.println(font.getPSName());

    sourceView.setFont(font);//  www .ja  v a 2s. c o m
    //sourceView.setFont(FontManager.getInstance().getFontInAction(attrs));

    sourceView.setContentType("text/xml; charset=UTF-16");

    // Instantiate a XMLEditorKit with wrapping enabled.
    XMLEditorKit kit = new XMLEditorKit(true);
    // Set the wrapping style.
    kit.setWrapStyleWord(true);

    sourceView.setEditorKit(kit);

    WordMLDocument editorViewDoc = (WordMLDocument) editorView.getDocument();

    try {
        editorViewDoc.readLock();

        editorView.getWordMLEditorKit().saveCaretText();

        DocumentElement elem = (DocumentElement) editorViewDoc.getDefaultRootElement();
        WordprocessingMLPackage wmlPackage = ((DocumentML) elem.getElementML()).getWordprocessingMLPackage();
        String filePath = (String) editorView.getDocument().getProperty(WordMLDocument.FILE_PATH_PROPERTY);

        //Do not include the last paragraph which is an extra paragraph.
        elem = (DocumentElement) elem.getElement(elem.getElementCount() - 1);
        ElementML paraML = elem.getElementML();
        ElementML bodyML = paraML.getParent();
        paraML.delete();

        Document doc = DocUtil.read(sourceView, wmlPackage);
        doc.putProperty(WordMLDocument.FILE_PATH_PROPERTY, filePath);
        doc.putProperty(WordMLDocument.WML_PACKAGE_PROPERTY, wmlPackage);
        doc.addDocumentListener(getToolbarStates());

        //Below are the properties used by bounce.jar library
        //See http://www.edankert.com/bounce/xmleditorkit.html
        doc.putProperty(PlainDocument.tabSizeAttribute, new Integer(4));
        doc.putProperty(XMLDocument.AUTO_INDENTATION_ATTRIBUTE, Boolean.TRUE);
        doc.putProperty(XMLDocument.TAG_COMPLETION_ATTRIBUTE, Boolean.TRUE);

        //Remember to put 'paraML' as last paragraph
        bodyML.addChild(paraML);

    } finally {
        editorViewDoc.readUnlock();
    }

    kit.setStyle(XMLStyleConstants.ATTRIBUTE_NAME, new Color(255, 0, 0), Font.PLAIN);

    sourceView.addFocusListener(getToolbarStates());
    //sourceView.setDocument(doc);
    sourceView.putClientProperty(Constants.LOCAL_VIEWS_SYNCHRONIZED_FLAG, Boolean.TRUE);

    return sourceView;
}

From source file:org.openmicroscopy.shoola.agents.fsimporter.view.ImporterUI.java

/**
 * Creates the component hosting the debug text.
 * //from   w  ww  . j ava2s . c  om
 * @return See above.
 */
private JComponent createDebugTab() {
    debugTextPane = new JTextPane();
    debugTextPane.setEditable(false);
    StyledDocument doc = (StyledDocument) debugTextPane.getDocument();

    Style style = doc.addStyle(STYLE, null);
    StyleConstants.setForeground(style, Color.black);
    StyleConstants.setFontFamily(style, "SansSerif");
    StyleConstants.setFontSize(style, 12);
    StyleConstants.setBold(style, false);

    JScrollPane sp = new JScrollPane(debugTextPane);
    sp.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent e) {
            try {
                debugTextPane.setCaretPosition(debugTextPane.getDocument().getLength());
            } catch (IllegalArgumentException ex) {
                //
            }
        }
    });
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(sp, BorderLayout.CENTER);
    return panel;
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/** Builds the UI component displaying the exception.*/
public static JTextPane buildExceptionArea() {
    StyleContext context = new StyleContext();
    StyledDocument document = new DefaultStyledDocument(context);

    JTextPane textPane = new JTextPane(document);
    textPane.setOpaque(false);//from   ww w . ja v  a  2s  .c o  m
    textPane.setEditable(false);

    // Create one of each type of tab stop
    List<TabStop> list = new ArrayList<TabStop>();

    // Create a left-aligned tab stop at 100 pixels from the left margin
    float pos = 15;
    int align = TabStop.ALIGN_LEFT;
    int leader = TabStop.LEAD_NONE;
    TabStop tstop = new TabStop(pos, align, leader);
    list.add(tstop);

    // Create a right-aligned tab stop at 200 pixels from the left margin
    pos = 15;
    align = TabStop.ALIGN_RIGHT;
    leader = TabStop.LEAD_NONE;
    tstop = new TabStop(pos, align, leader);
    list.add(tstop);

    // Create a center-aligned tab stop at 300 pixels from the left margin
    pos = 15;
    align = TabStop.ALIGN_CENTER;
    leader = TabStop.LEAD_NONE;
    tstop = new TabStop(pos, align, leader);
    list.add(tstop);

    // Create a decimal-aligned tab stop at 400 pixels from the left margin
    pos = 15;
    align = TabStop.ALIGN_DECIMAL;
    leader = TabStop.LEAD_NONE;
    tstop = new TabStop(pos, align, leader);
    list.add(tstop);

    // Create a tab set from the tab stops
    TabSet tabs = new TabSet(list.toArray(new TabStop[0]));

    // Add the tab set to the logical style;
    // the logical style is inherited by all paragraphs
    Style style = textPane.getLogicalStyle();
    StyleConstants.setTabSet(style, tabs);
    textPane.setLogicalStyle(style);
    Style debugStyle = document.addStyle("StyleName", null);
    StyleConstants.setForeground(debugStyle, Color.BLACK);
    StyleConstants.setFontFamily(debugStyle, "SansSerif");
    StyleConstants.setFontSize(debugStyle, 12);
    StyleConstants.setBold(debugStyle, false);
    return textPane;
}