Results 1 to 3 of 3
  1. #1
    kosmo76 is offline Member
    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    0

    Default update text output (eg. jLabel) during calculations

    Greetings all,

    Average-experienced in Java here, and relatively new to Swing.

    I am working on a tool that reads several files of raw data and makes heavy calculations upon pressing an "OK" button.
    The calculation routine takes a while to complete (may go up to a couple of hours).
    The final results are output in a jTextArea.

    My problem is that I would like to see some updating on the gui, probably in the form of a jLabel, informing the user about the calculation stage, progress etc...

    At first I naively added code within the flow, which puts some text inside a jLabel as soon as the calculations complete one stage (for example some boolean changing value). I soon realised that nothing is displayed within that jLabel until the entire calculation routine is complete, so the jLabel shows its text only when the jTextArea shows the final output.

    Sure, while working on NetBeans, I can see in the output console that intermediate output by simple system.out.println() commands. But still, I would like to make it right so that a 3rd user can read the intermediate output with only the Gui.

    I imagine that this might be asking for some event listener, but I can't seem to work my way through it. I would be grateful if you could point me at some direction.

    Thanks very much in advance.
    Last edited by kosmo76; 04-05-2011 at 10:05 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default

    You need to learn about SwingWorker and its publish and process methods.
    Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    db

  3. #3
    kosmo76 is offline Member
    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    0

    Default

    Yup, that's exactly what I needed. Took me a while to digest all this new level, but by the help of a few examples I was able to construct my SwingWorker outside the <jButtonActionPerformed> and with publish and process methods, it worked like a charm.
    Thanks again for taking the time to help !

Similar Threads

  1. Problem about JLabel not update in JPanel
    By fantasyme in forum Java Applets
    Replies: 11
    Last Post: 10-16-2011, 07:00 AM
  2. update a jlabel
    By niba10 in forum AWT / Swing
    Replies: 3
    Last Post: 04-04-2011, 07:43 PM
  3. Update JLabel during loop automatically
    By carnado2008 in forum AWT / Swing
    Replies: 4
    Last Post: 01-22-2011, 02:55 PM
  4. Jlabel update problem
    By fantasyme in forum AWT / Swing
    Replies: 3
    Last Post: 04-14-2010, 05:10 AM
  5. Problem altering text in JLabel
    By porchrat in forum New To Java
    Replies: 3
    Last Post: 06-29-2009, 12:37 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
  •