Results 1 to 16 of 16

Thread: Not working when file is imported

Threaded View

  1. #1

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Resolved Not working when file is imported

    Ok. In my the text editor I have been working on, I have methods that select or find parts of text. This works fine, but when you open a file, it doesn't.

    Here is the code to open a file:
    Code:
     public void processOpen()
     {
    	 /* process Opening a new file
    	 */
    	 returnVal = chooser.showOpenDialog(this);
    	 getFile = chooser.getSelectedFile().getPath();
    	 try {
    		 textArea2.read(new FileReader(getFile),null);
    	 }
    	 catch(IOException e)
    	 {
    		 e.printStackTrace();
    	 }
    	
    	 
     }
    Here is the code for finding text:
    Code:
      public void processFind()
     {
    	 /*  When the find method is invoked show an input dialg
    	  * process the string inputed and highlight the text
    	 */
    	String searchString = JOptionPane.showInputDialog("Enter the string to search for");
    	if (getFile == null)
    	{
    		String val = textArea2.getText();
    		int left = val.indexOf(searchString);
    		int right = left + searchString.length();
    		/*  Use the setSelectionStar() and setSelectionEnd()
    		*  methods to highlight the text
    		*/
    		textArea2.setSelectionStart(left);
    		textArea2.setSelectionEnd(right);
    	}
    	else if (getFile != null)
    	{
    	}
    	else 
    	{
    	}
     }

    And here is the code to select all:
    Code:
     public void processSelectAll()
     {
    	 /*  When Select all is clicked by the user
    	  *  process the starting and ending of the 
    	  *  text area and select all of it
    	  */
    	 String val = textArea2.getText();
    	 int left = val.indexOf(val);
    	 int right = left + val.length();
    	 /*  select it
    	  */
    	 textArea2.setSelectionStart(left);
    	 textArea2.setSelectionEnd(right);
    
     }


    I don't know why there would be conflict when I set the contents of the file to the text area.
    Can anyone help me with this?
    Last edited by System_Error; Dec 22nd, 2004 at 08:43 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width