-
Bug
-
Resolution: Fixed
-
P4
-
1.3.0
-
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)
======================================================================