• Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.3
    • client-libs
    • None
    • x86
    • windows_95



      Name: rlT66838 Date: 07/16/97


      I have created a editor using TextArea. I have the following 3 problems.

      1. Select the first character in the editor,use the TextArea::getSelectedText() or
      TextArea::getText()::substring(int, int);
         Empty string returned.

      2. Select the last character in the editor, use use the TextArea::getSelectedText() or
      TextArea::getText()::substring(int, int);
         StringIndexOutOfBoundsException thrown.

      3. Select any piece of text in the editor and use getSelectedText on it ()
          Incorrect text returned.


      The context menu which comes for free with TextArea or with the frame( I don't know which)
      implements clipboard support, which works cleanly.
      I want to provide clipboard support from the menu, that where I run into the above mentioned
      problems, when I try to retrieve the selected text.



      ======================================================================
      Another report from ###@###.###:

      Test Program :-
      Double click on each of the 4 words in the text field. The second to last word gives a result that
      is shifted right by one character, and the last word results in a StringIndexOutOfBoundsException.

      //----------------BugsII.java-----------------------
      import java.awt.* ;
      import java.awt.event.* ;
      import java.lang.* ;

      public class BugsII
      {

        //-----------------------------------------------------------------------//
        // The main routine. //
        //-----------------------------------------------------------------------//
        public static void main ( String args[] )
        {
          TestwII test = new TestwII ("BugsII") ;
        }
      }

      class TestwII extends Frame
                  implements MouseListener


      {
        TextArea ta ;
        public static String eol = System.getProperty ( "line.separator","*") ;

        //-----------------------------------------------------------------------//
        // Construct a text area window and insert some text. //
        //-----------------------------------------------------------------------//
        public TestwII ( String name )
        { super ( name ) ;
          setSize ( 100, 200) ;
          enableEvents (AWTEvent.WINDOW_EVENT_MASK ) ;
          enableEvents (AWTEvent.MOUSE_EVENT_MASK ) ;
          ta = new TextArea("",3,20,TextArea.SCROLLBARS_NONE) ;
          add ( ta ) ;
          ta.setText ("First Line");
          ta.append (eol) ;
          ta.append ("Hi Ho") ;
          ta.addMouseListener ( this ) ;
          setVisible ( true ) ;
        }

        //--------------------------------------------------------------------//
        // We overload the event handeling method so that we can look for the //
        // a) WINDOW_DESTROY event. //
        //--------------------------------------------------------------------//
        public void processEvent ( AWTEvent evt )
        { switch ( evt.getID() )
          { case WindowEvent.WINDOW_CLOSING :
              dispose() ;
              Runtime r = Runtime.getRuntime();
              r.exit(0);
            break ;
            default:
            break ;
        } }

        //---------------------------------------------------------------------//
        // This piece of code is extracted form a super set which allows me to //
        // extract a word from multi line text in a text frame. It works on //
        // Unix SGI 1.1.3 / SUN 1.1.5 but fails on Win95 1.1.3/1.1.4/1.1.5 //
        // 1) The words "first" and "next" can be highlighted with a double //
        // click and the correct word is returned by the "getSelectedText" //
        // call //
        // 2) The word "Hi" will be highlighted by a double click but the //
        // "getSelectedText" returns a "i H". i.e. it is off by one //
        // character and returns 3 characters. //
        // 3) The word "Ho" will be highlighted by a double click but the //
        // "getSelectedText" crashes with an out of range exeception. //
        // I have a 30,000+ line java development that has ground to a halt as //
        // we are unable to demonstraight on a Win95 laptop. //
        //---------------------------------------------------------------------//
        public void mouseClicked ( MouseEvent evt )
        {
          //-------------------------------------------------------------------//
          // Get the parameters that can be accessed from the super class. //
          // and the event. //
          //-------------------------------------------------------------------//
          int start = ta.getSelectionStart() ;
          int send = ta.getSelectionEnd() ;
          int clicks = evt.getClickCount() ;

      // System.out.println("Mouse Clicked "+evt.getClickCount()+ "times") ;
      // System.out.println(" start/end= "+start+"/"+send ) ;
      // System.out.println(" text " );
      // System.out.println(" eol length = "+eol.length() ) ;

          //-------------------------------------------------------------------//
          // HERE IS THE PROBLEM IF YOU DOUBLE CLICK ON THE "HO" WHICH IS THE //
          // LAST WORD ON THE LAST LINE YOU GET AN OUT OF RANGE ERROR UNDER //
          // Windows95. //
          //-------------------------------------------------------------------//

          String what = ta.getSelectedText() ;
          System.out.println(what) ;

        }

        public void mouseEntered ( MouseEvent evt )
        {
        }
        public void mouseExited ( MouseEvent evt )
        {
        }
        public void mousePressed ( MouseEvent evt )
        {
        }
        public void mouseReleased ( MouseEvent evt )
        {
        }
      }

      brian.klock@eng 1997-12-09
      ======================================================================

            ehawkessunw Eric Hawkes (Inactive)
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: