Example usage for javax.swing JTextPane getInputAttributes

List of usage examples for javax.swing JTextPane getInputAttributes

Introduction

In this page you can find the example usage for javax.swing JTextPane getInputAttributes.

Prototype

@BeanProperty(bound = false)
public MutableAttributeSet getInputAttributes() 

Source Link

Document

Gets the input attributes for the pane.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    int cp = 0;/*from www.j a  v  a2 s .  c o  m*/
    StyledDocument doc;
    JTextPane jta = new JTextPane();
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    doc = jta.getStyledDocument();
    JScrollPane jsp = new JScrollPane(jta);
    jsp.setPreferredSize(new Dimension(400, 400));
    String[] fnt = ge.getAvailableFontFamilyNames();
    MutableAttributeSet mas = jta.getInputAttributes();
    for (int i = 0; i < fnt.length; i++) {
        StyleConstants.setBold(mas, false);
        StyleConstants.setItalic(mas, false);
        StyleConstants.setFontFamily(mas, fnt[i]);
        StyleConstants.setFontSize(mas, 16);

        doc.insertString(cp, fnt[i] + "\n", mas);

        StyleConstants.setBold(mas, true);
        doc.insertString(cp, fnt[i] + "bold \n", mas);
        StyleConstants.setItalic(mas, true);

        doc.insertString(cp, fnt[i] + "bold and italic\n", mas);
        StyleConstants.setBold(mas, false);
        doc.insertString(cp, fnt[i] + "italic\n", mas);
    }
    JFrame frm = new JFrame();
    frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frm.setLayout(new BorderLayout());
    frm.add(jsp, BorderLayout.CENTER);
    frm.setLocation(100, 100);
    frm.pack();
    frm.setVisible(true);
}