Hi,
I committed the following patch which fixes returning the selected text of a
text component (tested for JTextField).

2006-02-07  Robert Schuster  <[EMAIL PROTECTED]>

        * javax/swing/text/JTextComponent.java:
        (getSelectedText): Calculate offset and use that as
        second argument.
Index: javax/swing/text/JTextComponent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/JTextComponent.java,v
retrieving revision 1.51
diff -u -r1.51 JTextComponent.java
--- javax/swing/text/JTextComponent.java	17 Jan 2006 16:57:03 -0000	1.51
+++ javax/swing/text/JTextComponent.java	7 Feb 2006 11:35:19 -0000
@@ -1241,9 +1241,15 @@
    */
   public String getSelectedText()
   {
+    int start = getSelectionStart();
+    int offset = getSelectionEnd() - start;
+    
+    if (offset <= 0)
+      return null;
+    
     try
       {
-        return doc.getText(getSelectionStart(), getSelectionEnd());
+        return doc.getText(start, offset);
       }
     catch (BadLocationException e)
       {

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to