1

I have created a leaf element of a branch of a document from the default root. I can see that the element is created but the element is not added to the root of the existing structure but I have given the parent as the default root .

Considering this code,

public class MyDoc extends DefaultStyledDocument  { 

//private static final long serialVersionUID = 1L;  

/**
 * 
 */
  public Element createBranchElement(Element parent,AttributeSet a) 
  {
      return super.createBranchElement(parent, a);
  } 

  protected AbstractElement createDefaultRoot(){
      return super.createDefaultRoot();
  } 

  protected Element createLeafElement(Element parent,AttributeSet a, String arg) throws BadLocationException 
  {
      return super.createLeafElement(parent, null, startOffset(arg),startOffset(arg)+1);
  } 

  protected void insertUpdate(AbstractDocument.DefaultDocumentEvent e, AttributeSet attr)
  {         
       Element root = getDefaultRootElement();        
       Element branchroot = new BranchElement(root, null);
       branchroot = createBranchElement(root,null);
       String pName = branchroot.getName();             
       Element leafElement = new LeafElement(branchroot, null, 0,0);
       try {
           leafElement = createLeafElement(branchroot,null,"p");
           //leafElement for a String  "p" should be created  
       } catch (BadLocationException e1) {
           // TODO Auto-generated catch block
               e1.printStackTrace();
       }

    }
}      
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140

1 Answers1

1

See http://java-sl.com/JEditorPaneTables.html how tables are inserted.

See protected void insertTable() method. Use the same approach to create your own specs and change this way the document structure.

StanislavL
  • 56,971
  • 9
  • 68
  • 98