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

JOptionPane doesn't disappear until next JOptionPane appears

I have a process that shows confirm messages from JOptionPane. This process is called from SwingUtilities.invokeLater(runnable) that is inside an Actionlistener for a JMenuItem. The code for the runnable is this: SwingUtilities.invokeLater(new…
Vegeta
  • 135
  • 6
2
votes
1 answer

invokeLater and the main class in NetBeans

I've been poking through the auto-generated code when making a new JFrame project with NetBeans, and came across this in my main method: java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new…
2
votes
1 answer

Should the first JFrame be created with 'invokeLater' or can it be created directly from main?

I've recently started learning how to use Swing and graphics in Java and have come across two different approaches for designing a GUI. 1) To have the program's main method in an instatiation of the JFrame class. 2) To have a class which calls…
kw3rti
  • 204
  • 2
  • 11
2
votes
1 answer

Is javax.swing.SwingUtilities.invokeLater nesessary?

So I have seen countless different GUI tutorials, and all of them have said to use this code: public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { …
2
votes
1 answer

Substance L&F not working

I want to use the Substance L&F library in my Java application, so I downloaded the .jar files and added them to the project classpath. Then I want to set the L&F in the application's main() function like this: SwingUtilities.invokeAndWait(new…
Matthias
  • 9,817
  • 14
  • 66
  • 125
2
votes
1 answer

Why cannot invokeLater method be used autonomously (using import javax.swing.SwingUtilities)?

The following code executes fine: public static void main(String [] args) { Runnable r = new Runnable() { public void run() { createGUI(); } } ; …
Buras
  • 3,069
  • 28
  • 79
  • 126
2
votes
1 answer

What is the difference showing JFrame using a invokeLater and without?

this is the documentacion: Causes doRun.run() to be executed asynchronously on the AWT event dispatching thread. This will happen after all pending AWT events have been processed. This method should be used when an application thread needs to…
WearFox
  • 293
  • 2
  • 19
2
votes
2 answers

Swing Runnable with parameters

I would like to run new Swing thread and pass a parameter into them. Something like this: String str; SwingUtilities.invokeLater(new Runnable() { public void run() { Play game = new Play(this.str); game.setVisible(true); } }); I…
Andrew
  • 958
  • 13
  • 25
2
votes
2 answers

SwingUtilities.invokeLater : Issues

I never understood SwingUtilities.invokeLater,that is the reason i kept avoiding it until now.But its very important to make Swing Thread safe. Well please excuse me, as this is my first time with this. I am trying to Close the window after some…
joey rohan
  • 3,505
  • 5
  • 33
  • 70
1
vote
2 answers

Thread is not returning back from SwingUtilities.invokeLater to main thread

I am writing my code in swing. To launch a private function of another class that can be called in awt thread . i simply write the code of that function in my class in SwingUtilities.invokeLater thread. main() { SwingUtilities.invokeLater(new…
Karn
  • 79
  • 8
1
vote
2 answers

InputVerifier changes button background

The code below shows just a textfield and a button. The textfield has got an inputVerifier which doesn't accept an empty field. As long as the verifier's "false" result is signalled by an optionPane, the button's background turns gray after…
Jörg
  • 214
  • 1
  • 9
1
vote
0 answers

Creating GUI and populating later the DefaultComboBoxModel of a JComboBox using SwingUtilities still freeze JFrame while populating thread is running

I try to create and show a GUI and to populate later a DefaultComboBoxModel using SwingUtilities.invokeLater(...). But the UI is still freezing and components are not displayed until the loading thread has completed. The main frame is instantiated…
1
vote
3 answers

BlackBerry - Thread not responding

I'm sorry that this question is a bit vague but I've not been able to get any useful info from debugging. I have a thread that I call using new Thread().Start, it will then run for a a short time and I receive this message: Uncaught…
Demonofloom
  • 240
  • 4
  • 17
1
vote
1 answer

Java Swing: cannot set JTextArea text in JDialog after it opens

I have a JTable where the last column is a JButton whose ActionListener is: private class EventDetailActionListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { EventQueue.invokeLater(new…
SagittariusA
  • 5,289
  • 15
  • 73
  • 127
1
vote
1 answer

Animations and SwingUtilities.invokeLater

I would like to use the method SwingUtilities.invokeLater so that all the Swing components of my program are updated by the event dispatch thread, since it is a good practice. But if I wrap all the code of the main method in…
Géry Ogam
  • 6,336
  • 4
  • 38
  • 67