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
4
votes
4 answers

How to view everything running on the event thread

We are experiencing a bug we cannot track down where something is freezing up our swing thread (it's been almost 2 weeks now and no real results) - we are experienced Swing programmers but we have a huge program and believe it to be in some of the…
sean.exposure
  • 63
  • 1
  • 5
4
votes
3 answers

How do I profile the EDT in Swing?

I have an application that I'm building in Swing. It has a scrollable and zoomable chart component which I can pan and zoom in. The whole thing is smooth except that sometimes the UI will pause for about 750 ms and I don't know why. This doesn't…
Erick Robertson
  • 32,125
  • 13
  • 69
  • 98
4
votes
1 answer

Implementing Runnable when using Java Swing

Learning a bit of Swing right now, came upon two tutorials which used different ways of making a simple JFrame window. First one implements Runnable and has a JFrame object variable in the class: class SwingDemo implements Runnable { private…
shengbojia
  • 83
  • 3
4
votes
3 answers

What's the correct way to run a code in the EDT only once?

I have a Swing application that uses a Java Thread to constantly perform some operation. The results of this operation update the contents of a graph in the UI: class ExampleThread { ... public void run() { while (running) { …
YuppieNetworking
  • 8,672
  • 7
  • 44
  • 65
4
votes
2 answers

Do JFrame windows in Swing run on their own separate threads?

I have three questions which are closely related in that they are born out of each other and represent a train of thought, so I am posting them under one question. It would not help me construct the big picture of my question if I posted them…
Water Cooler v2
  • 32,724
  • 54
  • 166
  • 336
4
votes
2 answers

When to use Thread.sleep over SwingTimer in 2D animation

The context in this case is creating a game loop that integrates with the model and updates the view once per frame. Listeners interface with the controller, controller updates the model, repaint() handles the view update from model (on an…
Gorbles
  • 1,169
  • 12
  • 27
4
votes
1 answer

What can cause the EDT not to (re)start

I am looking for possible causes for the EDT to shut down and not restart. More concrete, I have a test suite where occasionally one of the tests suffers from a time-out. The thread dump is always very similar to the following (where I stripped out…
Robin
  • 36,233
  • 5
  • 47
  • 99
4
votes
1 answer

Drawing a smooth circle with "trail"

Can I make a smooth circle that is constructing itself without a "wobbly" effect using Graphics2D? If yes, how? To understand what I mean you have to run the following example: import java.awt.Color; import java.awt.Color; import…
Lukas Rotter
  • 4,158
  • 1
  • 15
  • 35
4
votes
4 answers

Check if thread is EDT is necessary?

I have an UI implemented with Swing. One component does some work that may take some time, so I use SwingUtilities.invokeLater. However, I was reading some old code and found this in an ActionListener: if (!SwingUtilities.isEventDispatchThread()) { …
YuppieNetworking
  • 8,672
  • 7
  • 44
  • 65
4
votes
2 answers

Make thread run on non EDT (event dispatch thread) thread from EDT

I have a method running on the EDT and within that I want to make it execute something on a new (non EDT) thread. My current code is follows: @Override public void actionPerformed(ActionEvent arg0) { //gathering parameters from GUI //below code…
Aly
  • 15,865
  • 47
  • 119
  • 191
4
votes
2 answers

Is it possible to perform active rendering in Java Swing without being on the EDT?

I am looking into using Buffer Strategy and the following technique described on the Javadoc: // Main loop while (!done) { // Prepare for rendering the next frame // ... // Render single frame do { // The following loop ensures that the…
Pool
  • 11,999
  • 14
  • 68
  • 78
4
votes
3 answers

Disable button on click before actionPerformed is completed java

I have a button doing a long function, I want to disable this button after the user once click on it to in order to prevent him from clicking it again many times The button gets disabled but the problem is after the function finished the button…
Steve
  • 503
  • 3
  • 9
  • 19
4
votes
2 answers

Multiple Event Dispatch Threads causing deadlock in Java Web Start app

I am writing a Java Web Start application and I have observed it freezing. When I do a thread dump, I can see the two threads involved in the deadlock are both Event Dispatch Threads. When I run the app locally, there is only one EDT, but when I…
4
votes
2 answers

Flicker-free JComponent rendering within a Swing event handler

I'm writing a simple Java Swing application that is designed as a demo for a course. The purpose of the program is to visualize the progress of a recursive method (specifically, a recursive solution to a maze). I'd like to be able to update the…
nhowe
  • 909
  • 6
  • 14
4
votes
3 answers

JPanel added but not displayed "in time"

I have a JFrame that displays JPanels depending on the MenuItem you click. It works, but now I need to call a method once a JPanel is added to the frame and it is being shown (because I'm using JFreeChart inside that panel and I have to call…
Salvatorelab
  • 11,614
  • 6
  • 53
  • 80