• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Swing UI lag while adding rows to database table

 
Greenhorn
Posts: 5
Notepad Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a program that takes in log files, parses them, and inserts rows to a database that it connects to on startup. The GUI consists of two JButtons (one for importing and one for displaying data) and a JLabel to display the status.
Normally the GUI updates fine all the time (JLabel text change and disabling buttons), but when the program is inserting rows into the table, the whole GUI freezes until the operation completes, skipping all the UI changes that I make.
Is there any way to update the UI while I'm accessing the database?
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There sure is. Tutorial here: Lesson: Concurrency in Swing.
 
Justin Vasquez
Greenhorn
Posts: 5
Notepad Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the quick and useful reply.
I've gone through that, and I'm having little but of trouble understanding how to implement this. I currently have a main class that has the GUI and action listeners, and another that handles the database, including connecting and inserting.
Would the database class be a SwingWorker?
What do you recommend that I should do/how do you think I should implement it?
 
Paul Clapham
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. You should use the SwingWorker to run the code which updates the database. Your "database class" should have a method which does that, so that the SwingWorker can just call that method.
 
Justin Vasquez
Greenhorn
Posts: 5
Notepad Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much, using a SwingWorker fixed my problem.
I really appreciate it.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic