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

JTextArea.getLineEndOffset incorrect for last line w/o newline

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • client-libs
    • beta
    • x86
    • windows_98



      Name: boT120536 Date: 01/16/2001


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)



      import javax.swing.*;
      import javax.swing.text.*;
      class test
      {
          public static void main(String[] args) throws BadLocationException {
              JTextArea ta = new JTextArea();
              ta.setText("abc");
      System.out.println(ta.getText().length()); // 3
      System.out.println(ta.getLineCount()); // 1
      System.out.println(ta.getLineEndOffset(0)); // 4 (wrong)
      ta.append("\n");
      System.out.println(ta.getText().length()); // 4
      System.out.println(ta.getLineCount()); // 1
      System.out.println(ta.getLineEndOffset(0)); // 4 (right)
              System.exit(0);
          }
      }

      The above complete, compilable, runnable program illustrates the problem
      with getLineEndOffset, namely, that if the last line of the document does
      not end in a newline, the function returns a value one larger than it should
      be.
      (Review ID: 113918)
      ======================================================================

            shickeysunw Shannon Hickey (Inactive)
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: