Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Update GUI from thread

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Update GUI from thread

    Hi all.

    I'm new here and relatively new to java, usually specializing in web development languages.

    I have a multi-threading problem with a new application that i'm building which i hope someone might be able to shed some light on.

    I have a main class in which i set up a javafx GUI. On that GUI is a notification text element. This is responsible for displaying various different application status messages on the GUI itself. I also have another thread which sits in it's own class file from which i want to be able to update the GUI on certain actions. So lets say that the thread detects a key press or a mouse movement or something i want to make the GUI aware of this and update the notification Text element.

    Can anyone help me understand how this can be done?

    I've done a bit of research but i can't seem to find what i'm looking for, or i don't quite follow the examples.

    Cheers


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,180
    My Mood
    Hungover
    Thanks
    141
    Thanked 601 Times in 516 Posts

    Default Re: Update GUI from thread

    You should never make changes to the GUI from a thread other than the EDT. Recommended reading: Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,237
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: Update GUI from thread

    And more pertinent reading geared towards JavaFX in which the same principle Kevin mentioned applies
    Concurrency in JavaFX | JavaFX 2 Tutorials and Documentation

Similar Threads

  1. Using a invokelater to update gui is this correct?
    By jvasher in forum AWT / Java Swing
    Replies: 0
    Last Post: December 4th, 2012, 11:53 AM
  2. [SOLVED] GUI - Should it be in its own thread?
    By mds1256 in forum AWT / Java Swing
    Replies: 2
    Last Post: October 20th, 2012, 12:30 PM
  3. Replies: 1
    Last Post: October 31st, 2011, 12:22 PM
  4. Update GUI before lengthy task
    By hafunui in forum Java Theory & Questions
    Replies: 2
    Last Post: October 17th, 2011, 11:24 AM
  5. change JTable column name, gui does not update at once
    By renars in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 23rd, 2011, 10:39 AM