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
8
votes
5 answers

How to pass results from EDT back to a different thread?

I have the following use-case: I have code executing in Thread A (not EDT). Then I want to ask the user a question, but this must be done on the EDT as it involves Swing code (opening a dialog etc). Finally, I want to pass the user's answer back…
Eric Lindauer
  • 1,813
  • 13
  • 19
7
votes
1 answer

java SwingWorker.doInBackground() must not access GUI elements

May be this is trivial, I am struggling to understand a simple documentation on SwingWorker. Here is the copy pasted content Workflow There are three threads involved in the life cycle of a SwingWorker : Current thread: The execute() method is…
Jayan
  • 18,003
  • 15
  • 89
  • 143
7
votes
2 answers

IOException when opening JFileChooser

Ok this one is really weird. Every first time my application opens a JFileChooser it throws a IOException then some icons don't show properly. java.io.IOException at sun.awt.image.GifImageDecoder.readHeader(GifImageDecoder.java:265) at…
TecHunter
  • 6,091
  • 2
  • 30
  • 47
7
votes
3 answers

java swing clear the event queue

Is it possible to do this in a standard manner? Here is the scenario. Start doing something expensive in EDT (EDT is blocked till the expensive operation is over). While EDT was blocked, the user kept on clicking/dragging the mouse buttons. All the…
Santosh Tiwari
  • 1,167
  • 2
  • 14
  • 26
7
votes
2 answers

How does ignoring the event dispatch thread allow this program to work?

As I tried to see if I could answer this question earlier today. I realized that I don't fully understand the Event Dispatch Thread (EDT). Googling both confirmed and helped with that and clarified why I don't. (This might also be relevant to…
DSlomer64
  • 4,234
  • 4
  • 53
  • 88
7
votes
2 answers

SwingUtilities.invokeLater takes a Runnable and runs it on the EDT?

I am confused with the signature of SwingUtilities.invokeLater. It takes a Runnable object. Is it this Runnable object that is handed over to the Event Dispatch Thread? Why can't I directly call createAndShowGUI on the run method of EDT (if it is…
eagertoLearn
  • 9,772
  • 23
  • 80
  • 122
7
votes
1 answer

Is happens-before relation given in case of invokeLater() or invokeAndWait?

Pretty sure it is this way - but I like to know for sure - is happens-before relation given in case of invokeLater() or invokeAndWait()? The methods are defined in (SwingUtilities respectively) AWT.EventQueue. I guess there is synchronization…
7
votes
5 answers

Swing: Change cursor to wait cursor

See also Java Swing GUI hour glass. However the provided answer does not seem to work. I have following code: private void loadFileMenuItemActionPerformed(java.awt.event.ActionEvent evt) { int…
beginner_
  • 7,230
  • 18
  • 70
  • 127
7
votes
3 answers

Stop flickering in swing when i repaint too much

I am making an RPG with a tilemap. To generate the tilemap i loop through a 2 dimensional array but that means that when I repaint I have to do that each time. If I repaint too much the screen flickers how could I stop this. package…
sanchixx
  • 275
  • 2
  • 5
  • 12
6
votes
1 answer

Strange Crash issue as:- Dispatch queue: com.apple.root.default-overcommit-priority

I am developing an application in which a lot of operations are added in ASINetworkQueue.The operations are basically used for fetching the image from server and then in successful completion set the image in table view cell. Everything is happening…
Gypsa
  • 11,230
  • 6
  • 44
  • 82
6
votes
2 answers

updating a JProgressBar while processing

I know the subject has already been seen on many Questions and has been answered, but still, I can't get trough it. I just want to update a progressBar while extracting some stuff of a large xml file. I thought it was enough to have the…
user978548
  • 711
  • 2
  • 7
  • 12
6
votes
3 answers

How to indicate that a JComboBox is loading values?

I have a JComboBox whose values are retrieved across the net. I'm looking for a way to indicate that fact to the user, when the user wants to see the list, expands the drop down, and only then the data is being retrieved. The basic requirements…
Asaf
  • 2,480
  • 4
  • 25
  • 33
6
votes
2 answers

Multiple Event Dispatch Threads

I am new to Java Swing and my question is related to Event Queues and Dispatch threads. I read that it is possible to have multiple event queues , each per AppContext instance. Similarly does it mean each AppContext Event queue has its own event…
Sirish
  • 9,183
  • 22
  • 72
  • 107
6
votes
6 answers

Why is my JTextArea not updating?

I have code as follows: class SimplifiedClass extends JApplet { private JTextArea outputText; // Lots of methods public void DoEverything() { String output = ""; for(int i = 0; i <= 10; i++) { output +=…
Macha
  • 14,366
  • 14
  • 57
  • 69
6
votes
3 answers

What is the (event-dispatch) thread safe usage for JOptionPane.showMessageDialog and swing.utils.invokeAndWait?

I have a simple groovy script that from its main thread of execution needs to display some dialog boxes to the user. My swing knowledge is limited and rusty but I recall reading about the need to be careful to keep GUI stuff on the…
Alex Stoddard
  • 8,244
  • 4
  • 41
  • 61
1 2
3
51 52