java - Progress bar with indeterminate mode on a button click doesn't work -
i using netbeans , button click function. want progress bar run click on button. mode indeterminate because calling class writetofile
, work minutes in background , doesn't return value.
private void createfilebuttonactionperformed(java.awt.event.actionevent evt) { string str = (string) selecttypecombobox.getselecteditem(); createfilebutton.setenabled(false);// prevent more button presses string filepaths = filechooserwindow.getselectedfile().getabsolutepath(); string selecttype =(string) selecttypecombobox.getselecteditem(); writetofile writeobj; writeobj = new writetofile(filepaths,start,selecttype); try { writeobj.selecttype(); } catch (sqlexception | ioexception | runtimeexception ex) { system.exit(0); } }
got work:
jprogressbar1.setvisible(true); jprogressbar1.setindeterminate(true); executor executor = java.util.concurrent.executors.newsinglethreadexecutor(); executor.execute(new runnable(){ @override public void run(){ string str = (string) selecttypecombobox.getselecteditem(); createfilebutton.setenabled(false);// prevent more button presses string filepaths = filechooserwindow.getselectedfile().getabsolutepath(); string selecttype =(string) selecttypecombobox.getselecteditem(); writetofile writeobj; writeobj = new writetofile(filepaths,start,selecttype); try { writeobj.selecttype(); } catch (sqlexception | ioexception | runtimeexception ex) { system.exit(0); } jprogressbar1.setvisible(false); }
Comments
Post a Comment