• Post Reply Bookmark Topic Watch Topic
  • New Topic

Screen update

 
David Patterson
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • 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?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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 Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's an example of what I am talking about...

 
Thomas Smets
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two remarks to the code proposed :

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!