Graphic web design - Java Swing - O Reilly protected PlainDocument(AbstractDocument.Content c) Creates
Java Swing - O Reilly protected PlainDocument(AbstractDocument.Content c) Creates a new document using the specified Content. It adds a document property reflecting a default tab size of 8 and creates a default root element by calling createDefaultRoot(). 20.1.20.4 Protected Methods The only new methods defined in this class are the following protected methods. protected AbstractDocument.AbstractElement createDefaultRoot() Creates the Document’s default root element. The returned element is an AbstractDocument.BranchElement, containing a single empty Abstract- Document.LeafElement. protected void insertUpdate(DefaultDocumentEvent chng, AttributeSet attr) Indicates that content has been inserted into the Document. It refreshes the Element structure, adding and removing LeafElements as necessary to reflect the specified insert. If any Elements are added or removed by this method, indicating that lines have been added or removed, an ElementEdit (discussed at the end of the chapter) is created and added to the given event. protected void removeUpdate(DefaultDocumentEvent chng) Called to indicate that content has been removed from the Document. If the removal spans lines, the lines outside the removal range are joined together into a single Element. If this happens, the added and removed lines are used to create an ElementEdit (discussed at the end of the chapter), which is added to the given event. 20.1.20.5 Looking at PlainDocument’s Element Structures This example shows the Element structure used by PlainDocument using the AbstractDocument.dump() method. We start by printing the structure of an empty PlainDocument. We then add three lines of text and print again. Finally, we remove part of the first line, the entire second line, and part of the third line, showing how elements are removed and merged by the Document. Here’s the source for this simple example: // PlainDocExample.java// import javax.swing.text.*; public class PlainDocExample { public static void main(String[] args) { try { // Dump an empty document PlainDocument doc = new PlainDocument(); AbstractDocument.AbstractElement root = (AbstractDocument.AbstractElement) doc.getDefaultRootElement(); root.dump(System.out,0); System.out.println(”==========”); // Add 3 lines of text, dump again - 644
In case you need quality webspace to host and run your web applications, try our personal web hosting services.