java - why does my textArea not work in real time? -
i trying append string client program. made append statement in while loop. have affect in not working in real time?
for areas
tffixmsg.append( inputline + "\n\n\n");
and
tfcsvline.append(outputline+"\n\n\n");
it not show message on textarea until while loop done. how can make continue recieve messages client, , able output onto textarea in realtime
try { while ((inputline = in.readline()) != null) { system.out.println ("server: " + inputline); tffixmsg.append( inputline + "\n\n\n"); int pos = inputline.indexof(inputline, 0); h.addhighlight(50, 60, defaulthighlighter.defaultpainter); if (inputline.trim().equals("bye.")) { system.out.println("exit program"); break; } scanner input1 = new scanner(new file(csvname)); scanner input2 = new scanner(new file(csvname)); scanner input3 = new scanner(new file(csvname)); scanner input4 = new scanner(new file(csvname)); string csvline = getcsvlineval (getlocation34csv(gettag34value(tag34location(gettagcsv( parsefixmsg(inputline ,inputline))), getvaluecsv( parsefixmsg(inputline ,inputline))), getval34(input1, input2)), getcsvline( input3, input4) ); outputline = compareclientfixcsv( gettagcsv( parsefixmsg(inputline ,inputline)), getvaluecsv(parsefixmsg(inputline ,inputline)), getcsvtag(csvline), getcsvvalue(csvline)); out.println(outputline); tfcsvline.append(outputline+"\n\n\n"); input1.close(); input2.close(); input3.close(); input4.close(); } } catch (filenotfoundexception e) { // todo auto-generated catch block e.printstacktrace(); }
i guess, code runs not on edt
thread. if runs, should move other one.
then, can use other thread in order update swing ui elements:
swingutilities.invokelater(new runnable() { public void run() { tffixmsg.append( inputline + "\n\n\n"); // or whatever swing action want perform... } });
if need more sophisticated solutions try using swingworker
class.
Comments
Post a Comment