List of usage examples for javax.swing JTextPane getInputAttributes
@BeanProperty(bound = false)
public MutableAttributeSet getInputAttributes()
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); }