Questions tagged [invokelater]

A method provided by the SwingUtilities class in Java that executes asynchronously code on the AWT event dispatching thread in order to correctly manipulate UI elements.

SwingUtilities.invokeLater is a method provided by the Swing Library in Java in order to execute code on the AWT dispatching thread in an asynchronous fashion. As in the majority of graphical toolkits, an arbitrary thread is not allowed to update directly the UI but should asks the UI thread to execute it on its behalf.

Similar constructs exists in other UI toolkits (for example, in .NET there are Invoke/InvokeRequired methods in Windows Forms and the Dispatcher object in WPF).

This tag should be used to emphasize that invokeLater is used in the code, thus ruling out concurrency issues on the UI.

Related tags:

Additional resources:

  • The Java Tutorial has a chapter on invokeLater and invokeAndWait.
120 questions
23
votes
4 answers

Why to use SwingUtilities.invokeLater in main method?

After years of Java programming I always used to create my main() methods like this : public static void main(String[] args) { runProgram(); } But recently I studied some codes from the Web and saw this sometimes instead of the usual main()…
Rob
  • 15,732
  • 22
  • 69
  • 107
15
votes
3 answers

What is SwingUtilities.invokeLater

Possible Duplicate: What does SwingUtilities.invokeLater do? SwingUtilities.invokeLater I have seen this little piece of code hundreds of times: public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { …
11684
  • 7,356
  • 12
  • 48
  • 71
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
5 answers

Can anybody explain me this javax swing method?

I have trouble understanding this simple code: javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); Can anybody please explain me how it works (in simple terms because I am a newbie)?…
Roman
  • 124,451
  • 167
  • 349
  • 456
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
3 answers

Swing Splash screen with progress bar

This is my splash screen code, public class SplashScreen extends JWindow { private static final long serialVersionUID = 1L; private BorderLayout borderLayout = new BorderLayout(); private JLabel imageLabel = new JLabel(); private JProgressBar…
Praveen
  • 522
  • 1
  • 8
  • 17
6
votes
5 answers

Why does InvokeLater cause my JFrame not to display correctly?

Ok I've read an searched all over the web, and I've not found the solution to my problem yet, perhaps I'm missing something simple, hence here I am... I've got a rather large project, that handles work orders for a repair business. It's all database…
Marc
  • 63
  • 1
  • 4
5
votes
2 answers

How can I create an "event-driven" background thread in Java?

I like the simplicity of invokeLater() for sending units of work to the AWT EDT. It would be nice to have a similar mechanism for sending work requests to a background thread (such as SwingWorker) but as I understand it, these do not have any sort…
Chap
  • 3,649
  • 2
  • 46
  • 84
5
votes
1 answer

Difference between SwingUtilities.invokeLater and SwingWorker?

What is the difference between: //Some code, takes a bit of time to process (new SomeJFrame()).setVisible(true); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { (new…
Ernestas Gruodis
  • 8,567
  • 14
  • 55
  • 117
5
votes
3 answers

Create swing components at runtime

i created the application and it behaves pretty much as expected. the gui keeps responsive as long as the database query is running. when creating the custom panels with SwingUtilities.invokeLater() the gui freezes for a very short amount of…
5
votes
6 answers

Why should I use a separate thread to show a GUI in JAVA

This simple issue confuses me. You can display a JAVA GUI application by setting the frames' setVisible property true. But in almost all the examples I found on internet they use a separate thread to do the same thing. They do something like…
Anubis
  • 6,995
  • 14
  • 56
  • 87
5
votes
1 answer

Should i use SwingUtilities.invokeLater() inside of SwingWorker.doInBackground()?

The common way to interact with EDT from swing worker is useing get() method. But i have a long task and code like this: public Void doInBackground() { for(Object o : objects) { doSomething(); …
AvrDragon
  • 7,139
  • 4
  • 27
  • 42
4
votes
2 answers

Java Swing EDT & Concurrency

I was just wondering if it is still necessary to ensure synchronicity in an invokeLater() Runnable. I am encountering deadlock and need to overcome it while maintaining concurrency. Would this be an example of good code?: private String…
Whired
  • 259
  • 1
  • 11
4
votes
1 answer

Can't set a theme because of a stacktrace

I set my look and feel by doing this private void setSubstanceSkin(String theme) { try { UIManager.setLookAndFeel(new SubstanceBusinessBlackSteelLookAndFeel()); JFrame.setDefaultLookAndFeelDecorated(true); …
Tyluur
  • 95
  • 2
  • 10
3
votes
2 answers

JavaScript equivalent of SwingUtilities.invokeLater()

Is there any equivalent of Java's invokeLater() method of SwingUtilities in Javascript? UPDATE 1 So, will setTimeout() with zero delay do exactly the same as invokeLater()?
Dims
  • 47,675
  • 117
  • 331
  • 600
1
2 3 4 5 6 7 8