swing - Update Label text while button click action executing (Java) -
i have button , label on jframe. clicking on button try connect linux server , takes few second. want set label text connecting.. , connected.but doesn't set label text connecting .. during button operation executing. idea how that
private void buttonlconnectactionperformed(java.awt.event.actionevent evt) { labellout.settext("connecting"); string ip=""; string userid="username"; string password="password"; main_window.lboxconnect=new sshconnection(ip,userid,password); int x=lboxconnect.checkconnection(); if(x==1){ labellout.settext("connected"); if(dx==1) buttonbttinsert.setenabled(true); else lx=1; } else labellout.settext("connection failed"); }
you should long actions in background thread, not in button listener, otherwise ui seem frozen.
in listener, set text "connecting" , launch thread wrapping connection stuff. @ end of runnable, update text again once long operation has finished.
Comments
Post a Comment