Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4137805

DefaultStyledDocument.getParagraphElement() poorly documented

XMLWordPrintable

    • beta
    • sparc
    • solaris_2.5



      Name: akC57697 Date: 05/13/98



      The java.awt.swing.text.DefaultStyledDocument.getParagraphElement()
      returns element which getEndOffset() exceed the length of the document
      content.

      The doc says:
      "
      public Element getParagraphElement(int pos)

           Gets a paragraph element.
           Implements:
               getParagraphElement in interface StyledDocument
           Parameters:
               pos - the starting offset
           Returns:
               the element
      "
      The doc for Element.getEndOffset() says:
      "
      public int getEndOffset()

           Fetches the offset from the beginning of the document that this
           element ends at. If this element has children, this will be the end
           offset of the last child.
           Returns:
               the ending offset"

      --------------------->-8----------------------
      import java.awt.swing.text.*;
      public class test {
          public static void main(String s[]) {
           try {
            DefaultStyledDocument doc = new DefaultStyledDocument();
            String text = "The test text.";
            doc.insertString(0,text,null);
            int textlen = doc.getLength();
            Element elem=doc.getParagraphElement(0);

              if ( elem.getEndOffset()>textlen ) {
               System.out.println("The start offset:"+
                           elem.getStartOffset()+" end: "+ elem.getEndOffset());
               System.out.println("The length of text is: "+textlen);
               return;
              }
                 
           } catch (Exception e) {
               System.out.println("Unexpected:"+e);
               return;}
          }
      }
      ---------------------8-<----------------------
      Output JDK-1.2beta4-E:
      The start offset:0 end: 15 <-!!
      The length of text is: 14
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            akuzminorcl Alexander Kuzmin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: