Questions tagged [event-dispatch-thread]

The event dispatch thread, or EDT, is a special background thread which handles events from the Java GUI event queue. Swing and Android have different implementations but they are similar in concept.

This thread must never be stalled with some computationally intensive or otherwise slow task (like networking), as the GUI stops responding to user input until the call returns.

As Java GUI environments are not thread-safe, it is the only thread that can safely touch GUI components (instantiating and updating GUI components, including setting values for text fields and the like). If any other thread must do this, this should be done through a wrapper method that runs on the EDT. In Swing, the wrapper method is SwingUtilities.invokeAndWait or SwingUtilities.invokeLater. In Android, Activity.runOnUiThread serves the same purpose.

775 questions
11
votes
5 answers

Prevent Swing GUI locking up during a background task

I have a swing application which stores a list of objects. When the users clicks a button, I want to perform two operations on each object in the list, and then once that is complete, graph the results in a JPanel. I've been trying SwingWorker,…
Simonw
  • 852
  • 4
  • 12
  • 29
10
votes
4 answers

When to use SwingUtilies.invokeAndWait/invokeLater

I read somewhere that for any thread that affects the visuals of the gui it should be ran in the EDT using SwingUtilities.invokeAndWait/invokeLater For a basic gui, is it necessary to put something like new SwingGUI().setVisible(true); in the line…
10
votes
4 answers

How do you use the Event Dispatch Thread?

I learned about how swing isn't thread-safe. Delving deeper, I discovered that every modification to a swing component must be done on the Event Dispatch Thread in order to prevent various issues associated with multithreading. However, the…
Tharwen
  • 3,057
  • 2
  • 24
  • 36
10
votes
4 answers

How to choose an AWT-EventQueue thread, when there are several of them

I successfully injected my own Java code in a running Oracle Forms application, using DLL Injection and some jni trickery. (Windows 7, 32 bits, Oracle Forms 11, JRE Java 8) I am able to traverse the tree of Components and to query and set values in…
manuell
  • 7,528
  • 5
  • 31
  • 58
10
votes
4 answers

Swing verify code on Event Dispatch Thread at runtime

Are there any libraries that instrument code to verify that methods called on Swing components are called on the Event Dispatch Thread? It probably wouldn't be too difficult to write some basic code for doing this, but I'm sure there are edge cases…
Jeff Storey
  • 56,312
  • 72
  • 233
  • 406
10
votes
2 answers

Usage of JavaFX Platform.runLater and access to UI from a different thread

I have a few questions about Platform.runLater. I have a JavaFX Application class. In this class I run a thread (The thread reads data from a network socket). Now when I create a new Stage inside the thread, the system throws an execption (JavaFX…
swaechter
  • 1,357
  • 3
  • 22
  • 46
10
votes
4 answers

Issues: Creating a very accurate Swing Timer

In order to make SwingTimer accurate, I like the logic and example suggested by @Tony Docherty On CR. Here is the Link. In order to highlight the given words, again and again, there is always a few microsecond delays. If I have words to highlight…
joey rohan
  • 3,505
  • 5
  • 33
  • 70
10
votes
1 answer

JavaFx response to SwingUtilities.invokeLater

So I am aware that JavaFx's method of updating the GUI while using a thread is called Task but does the code work in similar way or are there any differences. let me give you a swing example: Another class outside the GUI that runs as a…
Marc Rasmussen
  • 19,771
  • 79
  • 203
  • 364
9
votes
2 answers

Java EventQueue. Why should everything be in invokelater method?

in the book that i'm reading, every example of GUI with multithreading has something like that: public static void main(String[] args) throws Exception { EventQueue.invokeLater(new Runnable() { public void run() { …
nicks
  • 2,161
  • 8
  • 49
  • 101
9
votes
4 answers

Where is the event dispatch thread called?

I read that all the code which constructs Swing components and handles Events must be run by the Event Dispatch Thread. I understand how this is accomplished by using the SwingUtilities.invokeLater() method. Consider the following code where the GUI…
Stormshadow
  • 6,769
  • 9
  • 33
  • 34
9
votes
2 answers

InvokeLater ordering with events

The EventQueue javadoc states that it is required that enqueued events are dispatched sequentially and in order. Is it correct that Runnables enqueued with EventQueue.invokeLater are guaranteed to be dispatched before subsequent user events (e.g. a…
user643011
  • 2,163
  • 3
  • 21
  • 38
8
votes
8 answers

How to manage the game state in face of the EDT?

I'm developing a real time strategy game clone on the Java platform and I have some conceptional questions about where to put and how to manage the game state. The game uses Swing/Java2D as rendering. In the current development phase, no simulation…
akarnokd
  • 69,132
  • 14
  • 157
  • 192
8
votes
2 answers

Swing - Update Label

I have a message label and a submit button. The submit button will be pressed multiple times, and the action for the each press can take up to a minute. When the button is pressed, I want to set the message to empty, and after the task is complete,…
Berek Bryan
  • 13,755
  • 10
  • 32
  • 43
8
votes
1 answer

How do I use javax.swing.text.AsyncBoxView to delegate text layout in JTextPane to a non-EDT thread?

I've hit the performance limits of JTextPane, while trying to implement a console style component. For the most part, my console behaves quite well, but attempts to spam it with large amounts of non- space separated text end up freezing the GUI…
predi
  • 5,528
  • 32
  • 60
8
votes
1 answer

Am I updating Swing component outside of EDT?

I've been reading a lot about Swing, threading, invokeLater(), SwingWorker, etc., but I just can't seem to get my head around it all, so I was trying to create a really simple program to illustrate. I've looked at a lot of examples, but none of…
1
2
3
51 52