JTextArea选中后不改变字体颜色
if(e.getActionCommand()=="替换"){//替换当前查找到的源词if(this.endOfText==true)return;StringBuffe...
if(e.getActionCommand()=="替换")
{//替换当前查找到的源词
if(this.endOfText==true) return ;
StringBuffer bufString=new StringBuffer(this.textArea.getText()); //原文本
String srcWord=this.srcWordField.getText(); //要替换的词
String desWord=this.desWordField.getText(); //替换后的词
pos=pos-srcWord.length();
bufString.delete(pos, pos+srcWord.length()); //删除源词
bufString.insert(pos, desWord); //插入目标词
pos=pos+desWord.length();
if(pos==bufString.length()) this.endOfText=true;
this.textArea.setText(bufString.toString());
} 展开
{//替换当前查找到的源词
if(this.endOfText==true) return ;
StringBuffer bufString=new StringBuffer(this.textArea.getText()); //原文本
String srcWord=this.srcWordField.getText(); //要替换的词
String desWord=this.desWordField.getText(); //替换后的词
pos=pos-srcWord.length();
bufString.delete(pos, pos+srcWord.length()); //删除源词
bufString.insert(pos, desWord); //插入目标词
pos=pos+desWord.length();
if(pos==bufString.length()) this.endOfText=true;
this.textArea.setText(bufString.toString());
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询