• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sync between Swing UI and work process  RSS feed

 
Michael Schmut
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to display the user a dialog box with a text (JLabel). In the same method, were i create the dialog, i start to scan a file. After the file scan is complete the dialog should be closed. It sounds easy, but i have a problem. JLabel will not display the text, i tried a second thread for gui and for the file scan, but i never saw the text.
When i forgotten the dispose for the dialog, the text will appear after the file scan. Where is my mistake??
Thanks
Michael
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swing and threads don't get a long very well. Especially when it comes to I/O. The only thing you can do is put the File read in the Thread. But it probably won't work. I/O is a processor hog. And so it Swing to an extent. you could try this though.
Create your Dialog, then call your thread, but call a sleep method inside your thread first, maybe that will give the GUI time to draw itself before I/O takes control of your processor.
Good Luck!!


------------------
Happy Coding,
Gregg Bolinger
 
Michael Schmut
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, it works. Now i have a new problem, but what is programming without problems :-) (ArrayIndexOutOfBoundsException in a table component, mystery)
Thanks

Michael
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!