invokelater

What is SwingUtilities.invokeLater [duplicate]

亡梦爱人 提交于 2019-12-18 03:19:09
问题 This question already has answers here : Closed 7 years ago . 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() { public void run() { createAndShowGUI(); } }); } Now my question is: what does invokeLater() do? What kind of bad things will happen if I just create and show my GUI inside the main thread? 回答1:

Is happens-before relation given in case of invokeLater() or invokeAndWait?

人盡茶涼 提交于 2019-12-12 15:21:24
问题 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 involved when something is entered in the EventQueue and hence as result of the synchronization, the happens-before relation and finally the visibility is given. But is it really that way? (and where can I find that information?) e.g. inside some worker

How does a Java thread synchronize with invokeLater()?

删除回忆录丶 提交于 2019-12-11 03:05:48
问题 I have a non-GUI thread that starts a JFrame using java.awt.EventQueue.invokeLater(new Runnable() { public void run() { cardReadPunchGUI = new IBM1622GUI(); // instantiate cardReadPunchGUI.setVisible(true); } }); Part of IBM1622GUI's constructor instantiates a "model" for itself, which my non-GUI thread needs access to: cardReadPunch = IBM1622GUI.getModel(); What is the correct way for my non-GUI thread to synchronize with the new GUI that's been "invoked later"? (Without synchronization, of

invokeLater vs invokeAndWait with JTextArea

痞子三分冷 提交于 2019-12-08 14:10:37
问题 I have a Swing application that runs on multiple threads, I created the Swing components on the EDT. An Executor launches threads that insert text to the JTextArea at some point. However, InvokeLater doesn't always do the appending, unlike InvokeAndWait. As I gathered it's aynchronous, non-blocking, but still should do the appending. How can it be? Thanks 回答1: Using EventQueue.invokeLater() to update a component's model from another thread is a necessary —but not sufficient —condition for

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

南笙酒味 提交于 2019-12-08 04:18:19
问题 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 showing only the title of it and not showing any contents of the JPanel additionally freezing the program (can't even press close button, have to go into task manager or eclipse to kill it). The second try was adding a method call in

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

时光毁灭记忆、已成空白 提交于 2019-12-06 21:30:28
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 showing only the title of it and not showing any contents of the JPanel additionally freezing the program (can't even press close button, have to go into task manager or eclipse to kill it). The second try was adding a method call in actionPerformed, and adding the method will this time call the main method of other class however the same result

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

谁说胖子不能爱 提交于 2019-12-06 07:18:28
问题 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 this, SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new Frame().setvisible(true); //just take the idea of this line } }); I found no difference between the two methods. But there must be some special reason, that's why

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

为君一笑 提交于 2019-12-06 03:10:55
问题 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(); MyGlobalGUIConsole.addMessage("Done for " + o); } } In most tutotials is recommended to use return values to get something back from SwingWorker to EDT, but can i just: public Void doInBackground() { for(Object o : objects) { doSomething(); SwingUtilities.invokeLater(new Runnable() { @Override public

Should Swing GUI application be controlled from Event Dispatcher or main thread?

感情迁移 提交于 2019-12-05 02:20:29
问题 I've read a few books about Java. In all of them there was at least one chapter teaching GUI programming. In all of them, creating a simple form application was following this logic: MyFrame.java public class MyFrame extends JFrame { JButton button1; public MyFrame() { button1 = new JButton("Click here."); } } FrameTest.java: public class FrameTest { public static void main(String[] args) { MyFrame myFrame = new MyFrame(); myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); myFrame

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

别说谁变了你拦得住时间么 提交于 2019-12-04 08:06:17
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(); MyGlobalGUIConsole.addMessage("Done for " + o); } } In most tutotials is recommended to use return values to get something back from SwingWorker to EDT, but can i just: public Void doInBackground() { for(Object o : objects) { doSomething(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { MyGlobalGUIConsole.addMessage("Done for " + o); } }); } } You can, but the SwingWorker has