List of usage examples for javax.swing JTextPane getDocument
public Document getDocument()
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); Element section = textPane.getDocument().getDefaultRootElement(); int paraCount = section.getElementCount(); for (int i = 0; i < paraCount; i++) { Element e = section.getElement(i); int rangeStart = e.getStartOffset(); int rangeEnd = e.getEndOffset(); String para = textPane.getText(rangeStart, rangeEnd - rangeStart); System.out.println(para); }//from w w w . ja v a 2 s .c o m }
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.setBold(style, true); doc.insertString(doc.getLength(), "Some Text", style); }
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); }
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.setItalic(style, true); doc.insertString(doc.getLength(), "Some Text", style); }
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.setFontFamily(style, "SansSerif"); // Append to document doc.insertString(doc.getLength(), "Some Text", style); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); StyledDocument doc = (StyledDocument) textPane.getDocument(); // Create a style object and then set the style attributes Style style = doc.addStyle("StyleName", null); StyleConstants.setFontSize(style, 30); doc.insertString(doc.getLength(), "Some Text", style); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); StyledDocument doc = (StyledDocument) textPane.getDocument(); // Create a style object and then set the style attributes Style style = doc.addStyle("StyleName", null); StyleConstants.setForeground(style, Color.white); // Append to document doc.insertString(doc.getLength(), "Some Text", style); }
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); }// w w w. ja va 2s . co m }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String s = new Date().toString(); JTextPane jtp = new JTextPane(); StyledDocument doc = (StyledDocument) jtp.getDocument(); SimpleAttributeSet normal = new SimpleAttributeSet(); StyleConstants.setFontFamily(normal, "SansSerif"); StyleConstants.setFontSize(normal, 16); SimpleAttributeSet boldBlue = new SimpleAttributeSet(normal); StyleConstants.setBold(boldBlue, true); StyleConstants.setForeground(boldBlue, Color.blue); SimpleAttributeSet highAlert = new SimpleAttributeSet(boldBlue); StyleConstants.setFontSize(highAlert, 18); StyleConstants.setItalic(highAlert, true); StyleConstants.setForeground(highAlert, Color.red); doc.insertString(doc.getLength(), s + "\n", normal); doc.insertString(doc.getLength(), s + "\n", boldBlue); doc.insertString(doc.getLength(), s + "\n", highAlert); f.add(jtp);//from w ww. j a v a2s . c o m f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); DefaultStyledDocument doc = (DefaultStyledDocument) textPane.getDocument(); Enumeration e1 = doc.getStyleNames(); while (e1.hasMoreElements()) { String styleName = (String) e1.nextElement(); System.out.println(styleName); Style style = doc.getStyle(styleName); int count = style.getAttributeCount(); System.out.println(count); Enumeration e = style.getAttributeNames(); while (e.hasMoreElements()) { Object o = e.nextElement(); if (o instanceof String) { String attrName = (String) o; Object attrValue = style.getAttribute(attrName); System.out.println(attrValue); } else if (o == StyleConstants.NameAttribute) { styleName = (String) style.getAttribute(o); System.out.println(styleName); } else if (o == StyleConstants.ResolveAttribute) { Style parent = (Style) style.getAttribute(o); System.out.println(parent.getName()); } else { String attrName = o.toString(); System.out.println(attrName); Object attrValue = style.getAttribute(o); System.out.println(attrValue); }/* w w w .ja v a2 s . co m*/ } } }