i'm creating parser that's why use jfilechooser. when select file jfilechooser, have jlabel says : "parsing in progress" or smth that. , when it's done : "parsing done".
(my first aim use progress bars, it's bit complicated me now)
the readfile class take array of files , create callable each file. if 5 files : 5 threads called. used callable because need strings of data each threads , write in same csv file.
well, when click on cancel on jfilechooser, jlabel displays correctly @ right moment when select files / file parsing function, jlabel waits entire execution of callables , "processing" appears (but when has ended ^^).
i cannot manage display processing @ beginning of threads.
note : called cardlayout @ moment, not used yet.
here code :
public class main { private static final string card_main = "card main"; private static final string card_file = "card file"; public static void main(string[] args) throws ioexception { creategui(); } public static void creategui(){ // jframe final jframe window = new jframe(); window.setdefaultcloseoperation(jframe.exit_on_close); window.setlocationrelativeto(null); window.settitle("tmg parser - thales"); window.setsize(400, 100); // buttonpanel ( 1 open jfilechooser & 1 quit ) jpanel container = new jpanel(); jpanel buttonpanel = new jpanel(); final jbutton filebutton = new jbutton("choose file"); filebutton.setbackground(color.black); filebutton.setforeground(color.white); final jbutton quitbutton = new jbutton("quit"); quitbutton.setbackground(color.red); quitbutton.setforeground(color.white); // adding buttons panel buttonpanel.add(filebutton); buttonpanel.add(quitbutton); // status label says : processing or done final jlabel status = new jlabel(); container.add(status); filebutton.addactionlistener(new actionlistener() { public void actionperformed(actionevent ae) { jfilechooser dialogue = new jfilechooser(new file(".")); dialogue.setmultiselectionenabled(true) ; if (dialogue.showopendialog(null)== jfilechooser.approve_option) { status.settext("processing"); file[] fichiers=dialogue.getselectedfiles(); for( int = 1; i<fichiers.length; ++i){ fichiers[i].getname(); fichiers[i].getabsolutepath(); } // calling execution function (threads) readfile readprogram = new readfile(fichiers); } else{status.settext("action cancelled");} } }); quitbutton.addactionlistener(new actionlistener() { public void actionperformed(actionevent ae) { system.exit(0); } }); window.add(container, borderlayout.center); window.add(buttonpanel, borderlayout.page_end); window.setvisible(true); } }
ok @tobias_k right ! thank man.
when launched readfile, freezing swing thread until readfile done.
i changed readfile thread (and calling callables), , works perfectly. !
Comments
Post a Comment