invokeandwait

Java happens-before relationship invokeAndWait

天涯浪子 提交于 2021-02-07 09:07:40
问题 My question is related to this question, which already has an answer: yes, there is a happens-before relationship imposed between actions of the thread calling invokeLater / invokeAndWait and actions on the EDT of the runnable thereby submitted. My question is a bit more general: Is it even possible to implement a method, such as invokeAndWait , such that it works properly , but not imposing a happens-before relationship? By the method working properly I mean the following: The submitted

Java happens-before relationship invokeAndWait

社会主义新天地 提交于 2021-02-07 08:58:56
问题 My question is related to this question, which already has an answer: yes, there is a happens-before relationship imposed between actions of the thread calling invokeLater / invokeAndWait and actions on the EDT of the runnable thereby submitted. My question is a bit more general: Is it even possible to implement a method, such as invokeAndWait , such that it works properly , but not imposing a happens-before relationship? By the method working properly I mean the following: The submitted

Java happens-before relationship invokeAndWait

血红的双手。 提交于 2021-02-07 08:57:21
问题 My question is related to this question, which already has an answer: yes, there is a happens-before relationship imposed between actions of the thread calling invokeLater / invokeAndWait and actions on the EDT of the runnable thereby submitted. My question is a bit more general: Is it even possible to implement a method, such as invokeAndWait , such that it works properly , but not imposing a happens-before relationship? By the method working properly I mean the following: The submitted

Error handling in SwingWorker

别来无恙 提交于 2020-01-11 08:54:29
问题 My question is a theory-based question, but it does meet a specific need I have. What do you do when your SwingWorker throws an Exception that you a) can anticipate and b) need to recover from and continue, but you want to notify the user that this error has happened? How do you grab the expected exception and notify the user without violating the "No Swing code from doInBackground() " rule? I have, in consideration of this problem, developed a SSCCE that I would like to put forth with the

Java Swing: main class wait until JFrame is closed

爷,独闯天下 提交于 2019-12-20 01:10:01
问题 I need some help with a simple java application which makes use of two jframe to get some input parameters. Here's a sketch of my code: //second jframe, called when the button OK of the first frame is clicked public class NewParamJFrame extends JFrame{ ... } //first jframe public class StartingJFrame extends JFrame{ private static NewParamJFrame newPFrame = null; private JTextField gnFilePath; private JButton btnOK; public StartingJFrame(){ //.. initComponents(); } private void initComponents

java - string return method is called before any value is assigned to string

两盒软妹~` 提交于 2019-12-13 09:39:27
问题 My application is supposed to read and write to a Serial Port. The data is read in the EventListener of the PortReader class. I wish to assign this data to a global String variable (private String sPortReaderString) for further use. The global string variable should return its value by using a method called getPortReader() which simply returns the string sPortReaderString. In the application's JFrame I open the serial port connection, send a command for which I automatically receive a reply

Java invokeAndWait?

∥☆過路亽.° 提交于 2019-12-11 06:34:07
问题 This is a really simple question about the invokeAndWait thing from swing utilities. I have heard that it synchronizes code execution on a single thread, but I'm not sure. If so, should I use invokeAndWait to do that? 回答1: SwingUtilities.invokeAndWait(Runnable) will enqueue the Runnable on the Event Queue. This will allow the Event Dispatching Thread to execute the run method of the Runnable within the context of the Event Dispatching Thread. invokeAndWait will not return until AFTER the EDT

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

Java API “Run on EDT if not on EDT”

血红的双手。 提交于 2019-12-07 10:28:00
问题 Just a musing about some repetitive code I have: Runnable run = new Runnable() { @Override public void run() { // Some EDT code } }; if (!EventQueue.isDispatchThread()) { SwingUtilities.invokeAndWait(run); } else { run.run(); } It's not terribly annoying, but it seems like there would be some proprietary function that checks this for you, although I haven't found it. 回答1: it seems like there would be some proprietary function that checks this for you There isn't. 回答2: Excluding Substance Look

Java API “Run on EDT if not on EDT”

﹥>﹥吖頭↗ 提交于 2019-12-05 14:27:55
Just a musing about some repetitive code I have: Runnable run = new Runnable() { @Override public void run() { // Some EDT code } }; if (!EventQueue.isDispatchThread()) { SwingUtilities.invokeAndWait(run); } else { run.run(); } It's not terribly annoying, but it seems like there would be some proprietary function that checks this for you, although I haven't found it. it seems like there would be some proprietary function that checks this for you There isn't. Excluding Substance Look and Feel I never needed to use invokeAndWait or testing for isDispatchThread / isEventDispatchThread , Substance