• 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

Screen update

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using Swing components for an application. I have a group of JTextFields that are used for output status for many parts of this application. As I do each part of the application, I set a status value in the JTextField -- one per section of the application. The status fields are not shown with the new values until the application ends. Then all of them are updated.
How can I get each JTextField to repaint with the new content?
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like you are updating the fields outside of the event thread... you'll need to explicitly run the update code in the event loop (see this IBM developer works article for details). Also, you should probably call invalidate() and/or validate() on the parent component of the textfields after you update their values so everything is layed out correctly.
 
David Patterson
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the info. I have rewritten the code so it uses the techniques you mention. But, the code works the same way. The code runs (I can see what is going on from the console screen and the System.out messages I also generate) to completion and then the screen updates.
I implemented a new class that refers to a JTextField and a String. These entries are stored in a Vector (thread-safe). My Runnable inner class that is invoked via the invokeLater method removes the first entry from the Vector and update the JTextField with the contents of the String.
The code runs to completion and then the JTextFields are updated.
I tried putting a Thread.yield() statement after calling the invokeLater method. No change.
The working logic of the program (no threads until this latest change) runs as a result of an ActionListener and a JButton being pushed in the GUI. So, the code may already be running in the right thread.
Any other suggestions?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's an example of what I am talking about...

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Two remarks to the code proposed :

 
She still doesn't approve of my superhero lifestyle. Or this shameless plug:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic