Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. How to create/set an element of a document

How to create/set an element of a document

Scheduled Pinned Locked Moved Java
tutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    prithaa
    wrote on last edited by
    #1

    Hello, I have a code like this

    public class Doc extends DefaultStyledDocument{
    }

    Doc doc= new Doc();
    doc.insertString(0, "This is a working document", null);
    AbstractDocument.AbstractElement rootElement = doc.createDefaultRoot();

    Once I create a root element how do I assign or set its value from the doc string.Currently the element is blank. thnaks Pritha

    P 1 Reply Last reply
    0
    • P prithaa

      Hello, I have a code like this

      public class Doc extends DefaultStyledDocument{
      }

      Doc doc= new Doc();
      doc.insertString(0, "This is a working document", null);
      AbstractDocument.AbstractElement rootElement = doc.createDefaultRoot();

      Once I create a root element how do I assign or set its value from the doc string.Currently the element is blank. thnaks Pritha

      P Offline
      P Offline
      padmanabanproject
      wrote on last edited by
      #2

      Am not adding full code .. jus sample import com.lowagie.text.*; Paragraph pH = new Paragraph("Title",FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.BOLD, new Color(0, 0, 255))); Paragraph pF1 = new Paragraph("Conditions Apply",FontFactory.getFont(FontFactory.HELVETICA, 7, Font.BOLD, new Color(0, 0, 255))); Paragraph pF2 = new Paragraph("*Coupon Valid till 1 month of date issued",FontFactory.getFont(FontFactory.HELVETICA, 7, Font.BOLD, new Color(0, 0, 255))); Paragraph pF3 = new Paragraph("*tamil translation"); Paragraph pNEXT = new Paragraph("\n"); Paragraph p3 = new Paragraph(); p3.add(new Chunk("")); Chunk separator = new Chunk(new DottedLineSeparator()); p3.add(separator); pH.setAlignment(Paragraph.ALIGN_CENTER); document.add(pH); document.add(pNEXT); document.add(tab); document.add(pNEXT); document.add(pF1); document.add(pF2); document.add(p3); //document; document.add(pNEXT);

      P 1 Reply Last reply
      0
      • P padmanabanproject

        Am not adding full code .. jus sample import com.lowagie.text.*; Paragraph pH = new Paragraph("Title",FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.BOLD, new Color(0, 0, 255))); Paragraph pF1 = new Paragraph("Conditions Apply",FontFactory.getFont(FontFactory.HELVETICA, 7, Font.BOLD, new Color(0, 0, 255))); Paragraph pF2 = new Paragraph("*Coupon Valid till 1 month of date issued",FontFactory.getFont(FontFactory.HELVETICA, 7, Font.BOLD, new Color(0, 0, 255))); Paragraph pF3 = new Paragraph("*tamil translation"); Paragraph pNEXT = new Paragraph("\n"); Paragraph p3 = new Paragraph(); p3.add(new Chunk("")); Chunk separator = new Chunk(new DottedLineSeparator()); p3.add(separator); pH.setAlignment(Paragraph.ALIGN_CENTER); document.add(pH); document.add(pNEXT); document.add(tab); document.add(pNEXT); document.add(pF1); document.add(pF2); document.add(p3); //document; document.add(pNEXT);

        P Offline
        P Offline
        prithaa
        wrote on last edited by
        #3

        hello thanks for your reply I am using swing libraries and there i am able to create a leaf or a branch of a document but the leafelement doesnt seem to get added to the default root .

        public class MyDoc extends DefaultStyledDocument {

        protected void insertUpdate(AbstractDocument.DefaultDocumentEvent e,
        AttributeSet attr){
        Element root = getDefaultRootElement();
        Element branchroot = new BranchElement(root, null);
        branchroot = createBranchElement(root,null);
        Element leafElement = new LeafElement(branchroot, null, 0,0);
        leafElement = createLeafElement(branchroot,null,"p");
        }

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

        protected Element createLeafElement(Element parent,AttributeSet a, String arg) throws BadLocationException
        {
        return super.createLeafElement(parent, null, startOffset(arg),startOffset(arg)+5);
        //complete code createleaf not written
        }

        }

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups