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
1 answer

Threading a paint method

I was wondering how I would thread the following code, or just a method in general: public void run (){ public void paint(Graphics g) { g.fillRect(20, 20, 20, 20); for (int i = 20; i < 1000; i++) { g.fillRect(20, i,…
4
votes
4 answers

Java Swing Thread changing UI - complications

I tried this for many hours.. I have a thread that changes a JTextField of my UI, which completely destroys the UI. The Thread (lets call it Thread A) is generated by an ActionListener. The .setText() function call is in a extra thread (B) created…
4
votes
1 answer

Thread interruption and ActionListener Java

I have a function graphics() that creates my JFrame and two JRadioButtons and adds ActionListeners to them. This graphics is called from main() and graphics itself calls game(). public void game() throws Exception { …
4
votes
2 answers

JFrame calling multiple concurrent Threads that updates a JProgressBar in the caller JFrame

This is how the thing goes: I have a JFrame for the main window of a Java application, that contains a panel with multiple JProgressBar. I want to start a Thread for each JProgressBar that will start another Threads on their own. When any of this…
4
votes
3 answers

Java Swing : GUI frozen - jstack interpretation

I have a Gui application in swing that prints a ticket on a serial thermal printer. When i hit the button that launch this action, my GUI is frozen. I think that's because the code is executed on the EDT. I used jstack to be sure but i don't…
caRameL
  • 633
  • 6
  • 15
4
votes
2 answers

not able to show data in a jTextField

I am writing a socket programming. It has GUI for server and client. In the server GUI there is a textfield which shows the word requested by user. But I am having problem in showing the word. I have tried txtWord.setText(sentword); It is not…
4
votes
1 answer

How can I make JFileChooser behave properly with disconnected network drives?

When I create a JFileChooser on a system with a disconnected network drive it takes forever before the JFileChooser gets displayed. It blocks the EDT for about 20s with a single disconnected network drive. It seems like it would be a common…
Ryan J
  • 2,502
  • 5
  • 31
  • 41
4
votes
3 answers

Trying To Update the JLabel in a Modal Dialog

I have a modal dialog containing a JLabel. This dialog calls a method in another class which does a long-running lookup activity. I'd like this lookup class to update the JLabel, which is passed from the modal dialog. I've tried updating the JLabel…
Elly
  • 63
  • 8
4
votes
2 answers

How to implement idle task in Java Swing

I have a GUI app that is getting to be quite slow. I want to start introducing timing for various GUI tasks - however, many of our GUI actions trigger other actions which then "invoke later" to trigger other actions. Eventually, it all settles down…
Paul Hollingsworth
  • 13,124
  • 12
  • 51
  • 68
3
votes
3 answers

Manage GUI and EDT in a multi-task application

I developed a Java application for creating and extracting an archive - like WinRAR. You can create several archives at the same time with multithreading. And recently, I wanted to add an information status during the archive creation in the form of…
damson
  • 2,635
  • 3
  • 21
  • 29
3
votes
1 answer

Swing invokelater freeze

im calling invokeLater direcly from button on actionPerformed with this code: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { SwingUtilities.invokeLater(new Runnable() { public void run() { int temp =…
Tom
  • 109
  • 2
  • 9
3
votes
3 answers

javax.swing.JFrame setText() in a loop? + intentional delay?

I am very new to Java (only been using it for about a week) and I'm working on a store simulator. Basically I just want to get basic things done right now like having a time until closing and a time since opening variable displayed on the screen. I…
snotyak
  • 3,709
  • 6
  • 35
  • 52
3
votes
3 answers

Detecting that JVM is shutting down

I have a Swing application that handles Ctrl+C using addShutdownHook(), and it works fine until one of the shutdown tasks I have calls a function that under normal circumstances changes a JLabel text, at which point it hangs. I assume the problem is…
Jason S
  • 184,598
  • 164
  • 608
  • 970
3
votes
3 answers

If EDT is a separate thread, why does invokeLater wait for the main thread to finish in this example?

So if Event Dispatch Thread is a separate thread from the main thread, that makes me think the next code would output Before Runnable true After But when i run it, it's as if the EDT waits for the main thread to finish before running the chunk of…
3
votes
6 answers

Background job running without affecting the rest of the gui

I'm asking for assistance concerning a general approach. I have written some java code to check my mailbox for unread mails on buttonclick. Now I want this code to permanently run in the background and check my mailbox every 2 minutes. Bad…