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

How to set divider location for JSplitPane on start-up

I have JPanel which contains JSplitPane. The JPanel is injected during a runtime into a JFrame using the method invokeAndWait. Then the invokeLater is called to update divider location in SplitPane. The problem is, when the divider update is…
Jakub Čech
  • 49
  • 1
  • 7
1
vote
1 answer

Calling JFileChooser twice in invokelater causes program not to exit

I am writing a program to collect information from two text files to add to tables in a database. In order to permit the user to select his own files I created a non-static method called chooseFile() that uses JFileChooser class to present a…
John Jones
  • 57
  • 4
1
vote
1 answer

Issues with invokeLater

I'm having issues updating a JLabel value using invokeLater. I have a separate method outside of the main function that runs invokeLater, but when I click the search button to update the value, it's not updating in the same instance of the gui. I…
user6680
  • 79
  • 6
  • 34
  • 78
1
vote
0 answers

invokelater not running after button click

I'm using invokeLater, but it isn't working how I want it to. I want it to update a jLabel after button click, but it's not outputting to the jLabel. My program finds the full computer name and then is supposed to update the jLabel within the same…
user6680
  • 79
  • 6
  • 34
  • 78
1
vote
3 answers

java updating UI components from another thread

I found many answers about my question, but I still don't understand why my application does not throw any exceptions. I created a new java form application in NetBeans 8. My form is created and displayed in main method like this: public static…
serban.b
  • 109
  • 1
  • 2
  • 10
1
vote
1 answer

Error in Java Program: "Move initializer to constructor"

Where it starts java.awt and public void run(), they are both underlined in red and when I click on them with my mouse, I get a message that says to move initializer to constructor. Can anyone help me with this? public static void main (String[]…
1
vote
1 answer

Main purpose of SwingUtilities invokeLater

I have this code snippet import javax.swing.SwingUtilities; public class Client1 { public static void main( String[] args ) { SwingUtilities.invokeLater( new Runnable() { public void run() { //new MyWindow(…
1
vote
0 answers

Do I need to use invokeLater() for addFocusListener methods?

I'm going through source code of large Swing GUI application. And I've noticed when they want to do something in case focusGained(Focus evn) or focusLost(Focus evn) they always use invokeLater(). Example: yourTextField.addFocusListener(new…
VextoR
  • 5,087
  • 22
  • 74
  • 109
1
vote
2 answers

What does EventQueue.invokeLater do and that vs start() Thread?

Hi im new in Opp and Java. I have see something about thread, implements Runnable , start() to call the call the run(). But what does this do? EventQueue invokeLater(); Or this full line that you can find in this post on the main…
DavidASG
  • 68
  • 6
1
vote
1 answer

SwingUtilities.invokeLater ... is there an invokeNow?

I had a problem earlier where I was trying to add objects to my canvas but the SwingUtilities.invokeLater hadn't really done its job yet. I really need to be able to add things reliably to this JPanel but I keep running into this same error. Is…
user1695505
  • 265
  • 2
  • 13
1
vote
2 answers

how do SwingUtilities.invokeLater(runnable) and Swing Timer work?

Case of study: I have a program with some model classes and some GUI classes in Swing where I use several threads in both of them which run an infinite loop with different sleep intervals for each runnable. two of model threads run a very critical…
Johnny
  • 1,509
  • 5
  • 25
  • 38
1
vote
2 answers

Java running main method of other class, when JButton is pressed

I am trying to develop a JFrame which has two buttons that would let me to call the main method of other classes. The first try was to put it directly into the actionPerformed of each button, this will cause the JFrame of the other class to open but…
1
vote
2 answers

InvokeLater() - will just once be enough?

I use the recommended code to start my interactive program, which uses Swing. : public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater( new Runnable() { public void run() { …
1
vote
3 answers

JFrame leaking memory?

So today I opened Task Manager and saw that my application leaks 200kbs of memory every second. I looked at my main loop: public final void run() { try { Thread.sleep(27); } catch (InterruptedException e1) { …
tambre
  • 4,625
  • 4
  • 42
  • 55
1
vote
1 answer

Successfully updating Look and Feel but still having errors

I am trying to update my look and feel without any errors, but I can't figure out what I am doing wrong. This is my Window class: public class Window extends JFrame { private static final long serialVersionUID = 1L; public Window() { …
user1834464