List of usage examples for javax.swing.text StyledDocument getLength
public int getLength();
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.setItalic(style, true); doc.insertString(doc.getLength(), "Some Text", style); }
From source file:Main.java
public static void main(String[] args) throws Exception { JTextPane textPane = new JTextPane(); StyledDocument doc = textPane.getStyledDocument(); Style style = textPane.addStyle("I'm a Style", null); StyleConstants.setForeground(style, Color.red); doc.insertString(doc.getLength(), "BLAH ", style); StyleConstants.setForeground(style, Color.blue); doc.insertString(doc.getLength(), "BLEH", 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.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 final void main(String[] args) throws Exception { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane textPane = new JTextPane(); textPane.addMouseMotionListener(new MouseAdapter() { public void mouseMoved(MouseEvent e) { AttributeSet style = getAttributes(e); if (style != null && StyleConstants.getIcon(style) != null) { textPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } else { textPane.setCursor(Cursor.getDefaultCursor()); }//from ww w. j a v a 2 s . c om } }); frame.add(new JScrollPane(textPane)); StyledDocument doc = (StyledDocument) textPane.getDocument(); SimpleAttributeSet style = new SimpleAttributeSet(); StyleConstants.setIcon(style, createImage()); doc.insertString(doc.getLength(), "this is a test", null); doc.insertString(doc.getLength(), "test", style); doc.insertString(doc.getLength(), "this is a test\n", null); doc.insertString(doc.getLength(), "another image", style); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); }
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 args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane pane = new JTextPane(); pane.setEditorKit(new CustomEditorKit()); pane.setText("Underline With Different Color"); StyledDocument doc = (StyledDocument) pane.getDocument(); MutableAttributeSet attrs = new SimpleAttributeSet(); attrs.addAttribute("Underline-Color", Color.red); doc.setCharacterAttributes(0, doc.getLength() - 1, attrs, true); JScrollPane sp = new JScrollPane(pane); frame.setContentPane(sp);/* w w w .j av a2 s.co m*/ frame.setPreferredSize(new Dimension(400, 300)); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) throws BadLocationException { JTextPane textPane1 = new JTextPane(); MutableAttributeSet black = new SimpleAttributeSet(); MutableAttributeSet red = new SimpleAttributeSet(); StyleConstants.setForeground(black, Color.black); StyleConstants.setForeground(red, Color.red); textPane1.setEditorKit(new StyledEditorKit()); doc1 = textPane1.getDocument();//from w w w .j a v a 2 s . co m append1("This is a Test!\n"); attribute = red; append1("Hello world! Hello Stackoverflow\n"); attribute = black; append1("the text is black again\n"); StyledDocument styledDocument = textPane1.getStyledDocument(); Element element; JTextPane textPane2 = new JTextPane(); textPane2.setEditorKit(new StyledEditorKit()); doc2 = textPane2.getDocument(); for (int i = 0; i < styledDocument.getLength(); i++) { element = styledDocument.getCharacterElement(i); AttributeSet attributeNew = element.getAttributes(); System.out.println(i); append2(styledDocument.getText(i, 1), attributeNew); } JFrame frame1 = new JFrame(); frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame1.setSize(400, 300); frame1.getContentPane().add(new JScrollPane(textPane1), BorderLayout.CENTER); frame1.setVisible(true); JFrame frame2 = new JFrame(); frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame2.setSize(400, 300); frame2.setLocation(300, 0); frame2.getContentPane().add(new JScrollPane(textPane2), BorderLayout.CENTER); frame2.setVisible(true); }