各位高手没事帮我指点一下迷津,Java怎么实现记事本中删除功能
如果在记事本文本框中输入了123123123123  我用鼠标选中第2个123  我想删除它 怎么做到的。最好能给个演示代码  谢谢!

解决方案 »

  1.   

    在文本框中选中某一个字符串,按下del键,它不是会自动删除吗?不需要自己实现吧
      

  2.   


    btn.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    String selectedStr = tf.getSelectedText();
    String newStr = tf.getText().replace(selectedStr, "");
    tf.setText(newStr);
    }
    });加了个按钮,给按钮加了个事件,貌似可行
      

  3.   

    各位高手 当响应记事本删除的菜单项时  怎么使得键盘上的delete被虚拟的按了一下
      

  4.   

    tf.setText(tf.getText().replace(tf.getSelectedText(), ""));那就这样
      

  5.   

    我刚才试了  API:
    replace(char oldChar, char newChar) 
              返回一个新的字符串,它是通过用 newChar 替换此字符串中出现的所有 oldChar 得到的。
      

  6.   

    String tem=tf.getText();
    tem=tem.substring(0,tf.getSelectionStart())+tem.substring(tf.getSelectionEnd()+1,tem.length());
    tf.setText(tem);
      

  7.   

    hh,我一直用“1234567890”测试的考虑不周全呐~~新手~~学习~~up~~