1 Replies - 1723 Views - Last Post: 27 May 2011 - 07:09 AM Rate Topic: -----

#1 jasser  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 03-July 09

how do i replace a word in jtextpane with another one i choose ?

Posted 27 May 2011 - 05:54 AM

using the code below i managed to change the word which is selected in the text ....
but i want to send the position of the word and change it ....
without having to select it !!!!!!
how can i do that ?
thx

 public void replacewrongword(String ritword )
    {
    	String scn= txtPad.getText().toString();
    	String last = scn.substring(scn.trim().lastIndexOf(" ")+1,scn.trim().length());
    	int start = txtPad.getText().indexOf(last);
    	txtPad.replaceSelection(ritword);
    	}



Is This A Good Question/Topic? 0
  • +

Replies To: how do i replace a word in jtextpane with another one i choose ?

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2553
  • View blog
  • Posts: 10,649
  • Joined: 20-September 08

Re: how do i replace a word in jtextpane with another one i choose ?

Posted 27 May 2011 - 07:09 AM

Why not just do the following?

txtPad.setText(txtPad.replaceFirst(wrongword, rightword));

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1