一个简单的方法:
把 JTextArea的text 读到一个字符串中,然后再编写对字符串的处理类,就可以了,

解决方案 »

  1.   

    使用JTextArea的以下方法进行处理
     int getLineCount() 
              Determines the number of lines contained in the area. 
     int getLineEndOffset(int line) 
              Determines the offset of the end of the given line. 
     int getLineOfOffset(int offset) 
              Translates an offset into the components text to a line number. 
     int getLineStartOffset(int line) 
              Determines the offset of the start of the given line. 
      

  2.   

    保留旧的getText(),用新的和它比较就能判断出是否被编辑过
      

  3.   

    怎样加一个CaretEvent事件呢?想利用getDo(),getMark().
      

  4.   

    下面这个类可以实现你的功能
    import javax.swing.JTextArea;
    import javax.swing.text.BadLocationException;/**
     * <p>Title:The JTextArea support to deletLine,getLineText,setLineText and insertLine </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2002</p>
     * <p>Company: </p>
     * @author z_yheart(年轻的心)
     * @version 1.0
     */public class MyTextArea extends JTextArea {  public MyTextArea() {
      }
      public void deleteLine(int Line) throws BadLocationException
      {
        int start=0;
        int end=0;
        try{
        start=this.getLineStartOffset(Line);
        end=this.getLineEndOffset(Line);
        }
        catch(BadLocationException ble)
        {
          throw ble;
        }
        this.replaceRange("",start,end);  }
      public void insertLine(String str,int Line) throws BadLocationException
      {
        int start =0;
        int end =0;    try{        start=this.getLineStartOffset(Line);    }
        catch(BadLocationException ble)
        {
           throw ble;
        }
        this.insert(str+"\r\n",start);
      }
      public void setLineText(String str,int Line) throws BadLocationException
      {
        int start =0;
        int end =0;  try{
        start=this.getLineStartOffset(Line);
        end=this.getLineEndOffset(Line);
        }
        catch(BadLocationException ble)
        {
          throw ble;
        }
        this.replaceRange("",start,end-1);
        this.insert(str+"\r\n",start);
      }
      public String getLineText(int Line) throws BadLocationException
      {
        int start =0;
        int end =0;
         String str="";
        try{
         start=this.getLineStartOffset(Line);
         end=this.getLineEndOffset(Line);
       str=this.getText(start,end);
        }
        catch(BadLocationException ble)
        {
          throw ble;
        }
        return str;
      }
    }