List of usage examples for javax.swing JTextPane JTextPane
public JTextPane()
JTextPane
. From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); DefaultStyledDocument doc = (DefaultStyledDocument) textPane.getDocument(); Enumeration e = doc.getStyleNames(); while (e.hasMoreElements()) { String styleName = (String) e.nextElement(); System.out.println(styleName); Style style = doc.getStyle(styleName); }/*from ww w . ja va2 s . c o m*/ }
From source file:PaneInsertionMethods.java
public static void main(String[] args) { final JTextPane pane = new JTextPane(); pane.replaceSelection("text"); pane.insertIcon(new ImageIcon("imageName.gif")); pane.insertComponent(new JButton("Click Me")); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(pane, BorderLayout.CENTER); frame.setSize(360, 180);/*from w ww. j a v a2 s . c o m*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); StyledDocument doc = textPane.getStyledDocument(); // Italicize the entire paragraph containing the position 12 doc.setParagraphAttributes(12, 1, textPane.getStyle("Italic"), true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); StyledDocument doc = textPane.getStyledDocument(); // Makes text italicized Style style = textPane.addStyle("Italic", null); StyleConstants.setItalic(style, true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); StyledDocument doc = textPane.getStyledDocument(); // Makes text 24pts Style style = textPane.addStyle("24pts", null); StyleConstants.setFontSize(style, 24); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); StyledDocument doc = textPane.getStyledDocument(); // A style can have multiple attributes; this one makes text bold and italic Style style = textPane.addStyle("Bold Italic", null); StyleConstants.setBold(style, true); StyleConstants.setItalic(style, true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); StyledDocument doc = textPane.getStyledDocument(); // Makes text red Style style = textPane.addStyle("Red", null); StyleConstants.setForeground(style, Color.red); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane ta = new JTextPane(); ta.setContentType("text/html"); ta.setText("<HTML><BODY><CODE> import java.io.*; <br> public class MyIO{}</CODE><br></BODY></HTML>"); JScrollPane jsp = new JScrollPane(ta); f.getContentPane().add(jsp);// w ww. java 2 s . com f.setSize(300, 200); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); StyledDocument doc = textPane.getStyledDocument(); Style style = textPane.addStyle("Red", null); StyleConstants.setForeground(style, Color.red); // Inherits from "Red"; makes text red and underlined style = textPane.addStyle("Red Underline", style); StyleConstants.setUnderline(style, true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); StyledDocument doc = (StyledDocument) textPane.getDocument(); Style style = doc.addStyle("StyleName", null); StyleConstants.setIcon(style, new ImageIcon("imagefile")); doc.insertString(doc.getLength(), "ignored text", style); }