Results 1 to 6 of 6
  1. #1
    intel i7 is offline Member
    Join Date
    Dec 2010
    Posts
    1
    Rep Power
    0

    Default Swing timers question?

    okay, so i have a GUI made using swing, and ever 5 seconds or so, i need to update part of the gui from a url. (output.setPage(url))

    so i have this running in a timer, the problem is, every time it goes to update, it makes my GUI hang. is there another way to do this that wont make it hang?

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Hang sense it's freeze is it?

    Seems to me you've done all in UI thread. Actually you must done UI handle in one thread and backend process in another thread(s).

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by intel i7 View Post
    okay, so i have a GUI made using swing, and ever 5 seconds or so, i need to update part of the gui from a url. (output.setPage(url))

    so i have this running in a timer, the problem is, every time it goes to update, it makes my GUI hang. is there another way to do this that wont make it hang?
    As Eranga states above, the Timer is not the problem. Rather the problem is likely htat your getting the url info on the main Swing thread or EDT (for Event Dispatch Thread). The solution will likely be to keep your Swing Timer, but have it create a SwingWorker object that gets the page in a background thread and then it can update your GUI on the EDT once the information has been obtained. Look up "Concurrency in Swing" for more information on this: Concurrency in Swing

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Cross-post: java - Scheduled tasks (Timers) in Swing - Stack Overflow

    OP: thanks for having us waste our time answering a question that was already answered in a cross-post, and thus ignoring our answers. If you have any consideration for us and others in the other forum, you will next time notify us in advance if you made any cross-posts and provide links to them. If you don't think that this (our free time) is important, than I'd prefer you not post again in this forum.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Swing question
    By Psyclone in forum New To Java
    Replies: 0
    Last Post: 02-02-2010, 11:50 PM
  2. Help - Swing Timers, Two Keypresses
    By Gheta in forum AWT / Swing
    Replies: 2
    Last Post: 07-29-2009, 10:23 PM
  3. Swing Timers Issue.
    By killpoppop in forum AWT / Swing
    Replies: 4
    Last Post: 03-10-2009, 12:17 AM
  4. Question on swing timers
    By Samgetsmoney in forum New To Java
    Replies: 5
    Last Post: 02-20-2009, 08:34 AM
  5. Swing Question, can you help?
    By Silentstormz in forum AWT / Swing
    Replies: 4
    Last Post: 09-21-2008, 04:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •