Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Knute Johnson Newsgroups: comp.lang.java.gui Subject: Re: Dynamic updation of a JTextArea Date: Wed, 14 Dec 2016 09:14:26 -0600 Organization: A noiseless patient Spider Lines: 44 Message-ID: References: <0f003cf3-2058-4286-8669-a75fe3f116c3@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 14 Dec 2016 15:13:03 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="ed04148e6ba6b10a9061889e072e8089"; logging-data="29199"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18/QjhGiXFX9+YkqqrLj69g" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 In-Reply-To: <0f003cf3-2058-4286-8669-a75fe3f116c3@googlegroups.com> Cancel-Lock: sha1:A5fHttCWCFcb3r7IJAnBLAC84nw= Xref: csiph.com comp.lang.java.gui:5502 On 12/14/2016 08:16, abhprk3926@gmail.com wrote: > I created a multi user chat system using sockets in java . everything > works perfect but a little issue. the common jtextarea where i am > supposed to display the chats ( its a app wherein all the users write > messages and the message of all the users is visible in their chat > space. Unfortunately the jtextarea is not updating itself whenever a > client writes a message . I tried doing like > System.out.print(contents of the common textarea) . In the command > prompt every single message written is displayed , which means the > code is working as intended . its just the textarea is not updating > itself. i searched many forums even tried doing the update thing in a > different thread than EDT but still i have the same problem. Can > anyone help me out ? Here is the code . > > public void run() { try { DataInputStream in = new > DataInputStream(client.getInputStream()); //client is the socket > object clientName = in.readUTF(); > //clientname is a string which stores the name of the clients > > s = "Joined"; SwingUtilities.invokeLater(new Runnable(){ public void > run() { clientChat.ta.append(clientName+": "+s); //clientchat > is the name of the Client class and ta is the common textarea object > which is declared as a static variable } }); > > while(!s.equals("terminate")) { s=in.readUTF(); > SwingUtilities.invokeLater(new Runnable(){ public void run() { > clientChat.ta.append(clientName+": "+s); } }); } > > }catch(Exception e){e.printStackTrace();} } > > every time a new client joins a new thread is created that acts as a > server for the client. this is the class where the updation of the > textarea is taking place. any help would be greatly praised. > I don't see anything obvious in your code but I'm only seeing a piece of it. I suggest you try making an SSCCE and duplicating your problem or maybe it will help you discover an answer. Oh and formatting your code a little more neatly would help too. Post an SSCCE here if you can't get it to work. -- Knute Johnson