![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e991. Inserting an Image into a JTextPane Componenttry { // Get the text pane's document JTextPane textPane = new JTextPane(); StyledDocument doc = (StyledDocument)textPane.getDocument(); // The image must first be wrapped in a style Style style = doc.addStyle("StyleName", null); StyleConstants.setIcon(style, new ImageIcon("imagefile")); // Insert the image at the end of the text doc.insertString(doc.getLength(), "ignored text", style); } catch (BadLocationException e) { }
e990. Enumerating the Paragraphs of a JTextPane Component e992. Inserting a Component into a JTextPane Component e993. Customizing Tab Stops in a JTextPane Component
© 2002 Addison-Wesley. |