Update jLabel content from the output of shell script

I have in a jFrame a jLabel that must update its content from the output of shell script. The execution of the shell script is made from a thread in another jFrame in which I store the output in a StringBuilder (public and static):

p = Runtime.getRuntime().exec("testpad -i -c"+can+" -n"+pad+" "+pathFile);
            final InputStream inStream = p.getInputStream();

            Thread uiThread = new Thread("UIHandler") {
                public void run() {
                  InputStreamReader reader = new InputStreamReader(inStream);
                  Scanner scan = new Scanner(reader);

                  while (scan.hasNextLine()) {


I update the jLabel (content in a jPannel) when the jPannel is showed:

private void jPanel1ComponentShown(java.awt.event.ComponentEvent evt) {                                       
    // TODO add your handling code here:


I think it is a race condition trouble but I put a Thread.sleep() with many second but the conten of jLabel don’t update.
I am doing this how example:

enter image description here

When I push the jButton the shell script print the output in the rectangle in red , then it opens a new jFrame with the jLabel that it should update but its don’t change. Where am I wrong? Thanks.

Source: shell

Leave a Reply