FileDocCategorySizeDatePackage
StyledText.javaAPI DocExample1081Sat Aug 24 21:33:54 BST 2002None

StyledText

public class StyledText extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

		JFrame jf = new JFrame("StyledText");
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Container cp = jf.getContentPane();

		JTextPane pane = new JTextPane();
		SimpleAttributeSet set = new SimpleAttributeSet();
		StyleConstants.setBold(set, true);

		// Set the attributes before adding text
		pane.setCharacterAttributes(set, true);
		pane.setText("Eine ");

		set = new SimpleAttributeSet();
		StyleConstants.setItalic(set, true);
		StyleConstants.setForeground(set, Color.red);
		StyleConstants.setBackground(set, Color.blue);

		Document doc = pane.getStyledDocument();
		doc.insertString(doc.getLength(), "Kleine ", set);

		set = new SimpleAttributeSet();
		StyleConstants.setFontSize(set, 24);

		doc.insertString(doc.getLength(), "Nachtmusic", set);

		JScrollPane scrollPane = new JScrollPane(pane);
		cp.add(scrollPane, BorderLayout.CENTER);

		jf.setSize(400, 300);
		jf.setVisible(true);