就像微软的记事本,点击查找,就在TextArea中定位到你要查找的字符串
我用setSelectionStart来定位字符串的头,setSelectionEnd定位尾位,可是
TextField和TextArea中如何比较他们是相同的字符串
ta.setSelectionStart(ibegin);
ta.setSelectionEnd(ibegin + strfind.length());
用到哪位方法?请指点
我用setSelectionStart来定位字符串的头,setSelectionEnd定位尾位,可是
TextField和TextArea中如何比较他们是相同的字符串
ta.setSelectionStart(ibegin);
ta.setSelectionEnd(ibegin + strfind.length());
用到哪位方法?请指点
System.out.println(strta.substring(i + strfind.length()-1));
if (strfind.equals(strta.substring(i, i + strfind.length() ))){
System.out.println(i);
ta.setSelectionStart(i);
ta.setSelectionEnd(ibegin + strfind.length());
break;
}
}
这段循环,在next按钮的事件处理这中,如果为true,Break,这时再点击next按钮,则继续查找.怎么做?
大家帮忙
find = new findJDialog(jwin);
find.text.setText("");
findNext.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e){
textArea.requestFocus(true);
String s=find.text.getText();
String str=textArea.getText();
int index=str.indexOf(s,find.count);
if(index!=-1) find.count=index+s.length();
if(index!=-1){
textArea.select(index,index+s.length());
}
else JOptionPane.showMessageDialog(null,"对不起,找不到\""+s+"\"!!");
find.text.requestFocus(true);
sl3=find.text.getText();
}
});
要查找的字符串与文件中字符串相等
的操作在哪里?
我的代码里有equalsif (cmd.equals("next")){ int i = 0;
String strfind = tffind.getText();
String strta = ta.getText();
strta = strta.replaceAll("\r\n"," "); int ibegin = strta.indexOf(strfind ,locate);
for(i = locate ;i<(strta.length()-strfind.length()); i++){
if (strfind.equals(strta.substring(i, i + strfind.length() ))){
ta.select(i,ibegin+strfind.length());
locate = i + 1;
break;
}else {locate= i + 1; }
}
}还有打开文件时不能换行