List of usage examples for javax.swing.text StyleContext getFont
public Font getFont(AttributeSet attr)
From source file:Main.java
public static void main(String[] args) { String HTMLTEXT = "<html><head><style>.foot{color:red} .head{color:black}</style></head>" + "<span style='font-family:consolas'>java2s.com</span><br/>" + "<span style='font-family:tahoma'>java2s.com</span>"; JTextPane textPane1 = new JTextPane(); textPane1.setContentType("text/html"); textPane1.setFont(new Font("courier new", Font.PLAIN, 32)); textPane1.setDocument(new HTMLDocument() { @Override/* w w w . ja v a 2 s. c om*/ public Font getFont(AttributeSet attr) { StyleContext styles = (StyleContext) getAttributeContext(); Font f = styles.getFont(attr); String ff = f.getFamily(); System.out.println(ff); return textPane1.getFont(); } }); textPane1.setText(HTMLTEXT); JFrame f = new JFrame(); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(textPane1)); f.setSize(320, 240); f.setLocationRelativeTo(null); f.setVisible(true); }