-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.1
-
None
-
x86
-
windows_nt
Name: mc57594 Date: 02/07/97
When retrieving selected text from a TextArea, getSelectedText(),
getSelectionStart(),
and getSelectionEnd() return incorrect values. The values are
generally down one line farther in the text than the actual
selected text.
The following code (which works correctly on JDK 1.0.2) gets the
currently selected text in a textfield named ta, and makes sure
that the entire line of text is selected.
/**
* Used to make sure that full lines are obtained from the selection
*/
private String findSelection() {
int start = ta.getSelectionStart();
int end = ta.getSelectionEnd();
String text = ta.getText();
System.out.println(start+" "+end+"\n"+ta.getSelectedText());
if(start < 0) start = 0;
if(end >= text.length() || end == -1) end = text.length()-1;
start = text.lastIndexOf('\n', start)+1;
if(text.charAt(start) == '\r') start++;
end = text.indexOf('\n', end);
if(start < 0) start = 0;
if(end >= text.length() || end == -1) end = text.length()-1;
ta.select(start, end);
System.out.println(start+" "+end+"\n"+ta.getSelectedText());
return ta.getSelectedText();
}
company - John Deere, WWAG Division , email - ###@###.###
======================================================================
- duplicates
-
JDK-4072264 getSelectedText, getSelectedStart/End in TextArea class returns wrong
- Closed