java - How to append StringBuilder to textarea while replacing the previous string builder that was there? -
so string.append
, string2.append
stringbuilder
objects made load words text file faster, problem when switch radio button occurrence , alphabetical adds text area instead of replacing previous list. ideas on how fix this?
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()); }
you may looking replacerange()
, "simply delete if new string null or empty." can insert()
new text @ position 0
.
textarea.replacerange(null, 0, 0); textarea.insert(string2.tostring(), 0);
addendum: this above not work.
both replacerange()
, settext()
correctly clear text area when supplied null
or empty string
. latter illustrated in complete example. may have problem elsewhere in code, verify all swing gui objects constructed , manipulated only on event dispatch thread. note in particular append()
no longer thread safe.
Comments
Post a Comment