Error Cannot Call Invokeandwait From The Event Dispatcher Thread
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up SwingUtilities.invokeAndWait not running up vote 1 down vote favorite The code within the run() method is not being executed. Can anyone tell me why? startButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if(creator == null) { String[] args = getArguments(); try { writeSettingsFile(args); } catch(IOException io) {} consolePanel.addLine("Starting..."); bar.setIndeterminate(true); try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { MessageConsole console = new MessageConsole(getConsole().getTextPane(), self, null); console.redirectOut(new Color(240, 240, 240), null); console.redirectErr(Color.RED, null); console.setMessageLines(consolePanel.getHeight() / 17); try { SomeApp.main(getArguments()); } catch (Exception ex) { Logger.getLogger(OSXWorldPanel.class.getName()).log(Level.SEVERE, null, ex); } } }); } catch (InterruptedException ex) { Logger.getLogger(OSXWorldPanel.class.getName()).log(Level.SEVERE, null, ex); } catch (InvocationTargetException ex) { Logger.getLogger(OSXWorldPanel.class.getName()).log(Level.SEVERE, null, ex); } } } }); Throws Error: Exception in thread "AWT-EventQueue-0" java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread at java.awt.EventQueue.invokeAndWait(EventQueue.java:1017) at javax.swing.SwingUtilities.invokeAndWait(SwingUtilities.java:1320) java swing swingutilities share|improve this question edited Jan 7 '11 at 20:57 asked Jan 7 '11 at 20:34 Jakir00 74821126 Are you sure it is not? Have you put some System.out.println()s in? –jzd Jan 7 '11 at 20:37 I am sure. When I press the button the run() method is not called. Even with println's it will display no
This Site Careers Other all forums Forum: Threads and Synchronization Cannot call invokeAndWait, can't invokeLater either Sam Smith Greenhorn Posts: 17 posted 9 years ago Hi all, I'm writing a small class that part of a much larger application that I can't modify. The class is supposed to open a java program and return a JPanel representing the program's output window. That JPanel will then display in the main program's JFrame. Here is a snippet of my code: public JPanel getJPanel(String[] args) { WaveInterferenceApplication waveApp = new WaveInterferenceApplication(args); JFrame frame = waveApp.getJFrame(); JPanel panel = (JPanel) frame.getContentPane(); return panel; } This code works fine http://stackoverflow.com/questions/4630043/swingutilities-invokeandwait-not-running if I create a little main method in this class which gets this JPanel and sticks in in a new JFrame. Nothing wrong there. However, when the main program tries to get the JPanel to place it in the JFrame, I get: Exception in thread "AWT-EventQueue-0" java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread at java.awt.EventQueue.invokeAndWait(EventQueue.java:834) at javax.swing.SwingUtilities.invokeAndWait(SwingUtilities.java:1257) at edu.colorado.phet.waveinterference.WaveInterferenceApplication.
call invokeAndWait from the event dispatcher thread http://javarevisited.blogspot.com/2011/09/invokeandwait-invokelater-swing-example.html Summary: java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread Status: RESOLVED FIXED Product: db Classification: Unclassified Component: Show Data Version: 6.x Hardware: All All Priority: P1 (vote) TargetMilestone: TBD Assigned To: _ ahimanikya error cannot QA Contact: issues@db URL: Whiteboard: Keywords: Depends on: Blocks: Show dependency tree /graph Reported: 2008-06-12 13:01 UTC by Andrei Badea Modified: 2008-06-14 22:09 UTC (History) CC List: 0 users See Also: Issue Type: DEFECT Exception Report : Attachments Stack trace error cannot call (2.77 KB, text/plain) 2008-06-12 13:02 UTC, Andrei Badea Details View All Add an attachment (proposed patch, testcase, etc.) Note You need to log in before you can comment on or make changes to this bug. Description Andrei Badea 2008-06-12 13:01:54 UTC ... when executing a statement. Comment 1 Andrei Badea 2008-06-12 13:02:30 UTC Created attachment 62750 [details] Stack trace Comment 2 _ ahimanikya 2008-06-14 22:09:21 UTC Fixed in the latest drop http://wiki.netbeans.org/attach/DatabaseShowDataModuleReview1/DataViewSuite.zip?version=10 Format For Printing -XML -Clone This Bug -Top of page First Last Prev Next This bug is not in your last search results. SiteMap About Us Contact Legal & Licences By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by
in Java Swing (an example tutorial) Everyone who is doing programming in java swing has to come across invokeAndWait and invokeLater provided by SwingUtilites. In this java swing tutorial we will learn about both invokeLater() and invokeAndwait() method. In first part we will mostly focus on invokeLater and will find answers to questions like What is invokeLater, how to use invokelater in java swing, example of invokelater in swing etc while in second part of this invokeLater tutorial we will learn more about invokeAndWait method in java swing and will learn Why we need InvokeAndWait, how to use InvokeAndWait method in java Swing and differences between invokelater and invokeAndWait. Finally, we will see a code example of both invokeLater and invokeAndWait in Swing and will be able to decide when to use invokeLater and when to use invokeAndWait while doing Swing programming. We will also see famous Swing interview questions "difference between invokeLater and invokeAndWait" at the end of the article. Why do we need InvokeLater method in Swing? Before using invokelater or going deep about invokelater lets see why do we need this method in swing utility class? As we all know java swing is not threadsafe , you can not update swing component like JButton, JLable , JTable or JTree from any thread , they all needs to be updated from just one thread and we call it Event Dispatcher thread or EDT in short. Event Dispatcher thread is used to render graphics for java swing component and also process all events corresponding to a key press, mouse click or any action. So if you want to update a particular swing component suppose label of a JButton from Yes to No you need to do this in Event Dispatcher thread and for doing this you need InvokeLater. invokeLater is used to perform any task asynchronously on AWT Event Dispatcher thread. What is invokeLater in Java Swing The invokeLater() is a method in java on swing package and belongs to SwingUtilities class. Invokelater is used by java swing developer to update or perform any task on Event dispatcher thread asynchronously.invokeLater has been added into Java API from swing extension and it belongs to SwingUtilities class. How does invokeLater works in Java Swing If you see the signature of invokeLater method you will find that invokeLater takes a Runnable object and queues it to be processed by EventDispatcher thread. EDT thread will process t