簡體   English   中英

添加到textarea中,有沒有比追加更快的方法? 如何一次不一次一行地添加整個列表……JAVA

[英]adding to a textarea, is there a faster way than appending? How to add a whole list at one time not line by line…JAVA

我正在使用Java,此程序基本上是在分析txt文件,並使用N(整數1-4)創建一個超級字符串來分析txt文件。 我讓它們使用單​​選按鈕按字母順序排列並按順序排序。.我的問題是如何一次添加整個列表,而不是逐行添加,我覺得逐行添加到我的textareas效率不高。 有什么建議么? 我為每個語句逐行添加並保持計數。

     String[] storage = new String[N];
    words = new CountLinkedList<SuperString>();
    words2 = new OrderedLinkedList<SuperString>();
   for(int i=1;i<N;i++)
     storage[i] = scan.next().toLowerCase().replace(",","").replace(".","");

    while(scan.hasNext())
    {
      for(int i=0;i<=N-2;i++)
        storage[i] = storage[i+1];
      storage[N-1] = scan.next().toLowerCase();
      storage[N-1] = storage[N-1].replace(",","").replace(".","");
      SuperString ss = new SuperString(storage);
      SuperString ss2= new SuperString(storage);
      words.add(ss );
      words2.add(ss2 );
    }

    textarea.setText("");
    textarea.append("    "+filename+" has wordcount: "+words.size()+
      "\n-------------------------\n\n");
        }
    SuperString[] ss = new SuperString[words.size()];
    SuperString[] ss2 = new SuperString[words2.size()];
    int i=0;
    int count =0, count2= 0;


    for(SuperString word: words)
    {
      ss[i] = word;
      i++;
    }
    int j=0;
    for(SuperString word: words2)
    {
      ss2[j] = word;
      j++;
    }


    Arrays.sort(ss, new SuperStringCountOrder());

   if(occurrence.isSelected())
    {
     textarea.setText("");
    for(SuperString word : ss)
    {
      count++;
        textarea.append(count+"   "+ "  "+word+"\n");     
    }
    }
    if(alphabetical.isSelected())
    {
      textarea.setText("");

     for(SuperString word : ss2)
    {
       count2++;
        textarea.append(count2+"   "+ "  "+word+"\n");     
    }

這樣很好! 但是,當我追加到textarea時,即使我每次選擇出現和按字母順序都具有textarea.setText(“”)時,它仍保留舊列表並僅添加到舊列表中?

  for(SuperString word : ss)
    {
      count++;
      string.append(Integer.toString(count)+ "       "+ word+ "\n");
      string.toString();
    }
    if(occurrence.isSelected())
    {
     textarea.setText("");
     textarea.append("    "+filename+" has wordcount: "+words.size()+
      "\n-------------------------\n\n");
     textarea.append(string.toString());
    }


     for(SuperString word : ss2)
    {
       count2++;
       string2.append(Integer.toString(count2)+ "       "+ word.toString()+ "\n");  
    }
         if(alphabetical.isSelected())
    {
      textarea.setText("");
      textarea.append(string2.toString());

    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM