Swing: what to do when a GUI update takes too long and freezes other GUI elements?
Posted
by java.is.for.desktop
on Stack Overflow
See other posts from Stack Overflow
or by java.is.for.desktop
Published on 2010-04-07T10:48:29Z
Indexed on
2010/04/07
10:53 UTC
Read the original article
Hit count: 287
Hello, everyone!
I know that GUI code in Java Swing must be put inside
SwingUtilities.invokeAndWait
or SwingUtilities.invokeLater
.
This way threading works fine.
Sadly, in my situation, the GUI update it that thing which takes much longer than background thread(s). More specific: I update a JTree with about just 400 entries, nesting depth is maximum 4, so should be nothing scary, right? But it takes sometimes one second! I need to ensure that the user is able to type in a JTextPane without delays. Well, guess what, the slow JTree updates do cause delays for JTextPane during input. It refreshes only as soon as the tree gets updated.
I am using Netbeans and know empirically that a Java app can update lots of information without freezing the rest of the UI.
How can it be done?
NOTE 1: All those DefaultMutableTreeNode
s are prepared outside the invokeAndWait
.
NOTE 2: When I replace invokeAndWait
with invokeLater
the tree doesn't get updated.
© Stack Overflow or respective owner