event-dispatch-thread

Starting threads from inside EDT event handler code in Swing apps

喜夏-厌秋 提交于 2021-02-19 08:11:26
问题 My understanding of the Swing Event Dispatcher Thread (EDT) is that its a dedicated thread where event handling code is executed. So, if my understanding is correct, then in the example below: private class ButtonClickListener implements ActionListener{ public void actionPerformed(ActionEvent e) { // START EDT String command = e.getActionCommand(); if( command.equals( "OK" )) { statusLabel.setText("Ok Button clicked."); } else if( command.equals( "Submit" ) ) { statusLabel.setText("Submit

Java: Updating UI while waiting for another thread to finish

匆匆过客 提交于 2021-02-11 15:05:59
问题 I have some Java Swing login panel. When user click "login" button, extensive DB communication takes place. I got an idea to put that db communication into another thread (that db communication is used for filling some hash maps and singletons). After putting that communication into separate thread, db heavy lifting takes place while user is typing it's uname and password. When user clicks "login" button, than code will wait for "heavy lifting" thread to join, and then proceed. The problem is

Java: Updating UI while waiting for another thread to finish

不打扰是莪最后的温柔 提交于 2021-02-11 15:01:35
问题 I have some Java Swing login panel. When user click "login" button, extensive DB communication takes place. I got an idea to put that db communication into another thread (that db communication is used for filling some hash maps and singletons). After putting that communication into separate thread, db heavy lifting takes place while user is typing it's uname and password. When user clicks "login" button, than code will wait for "heavy lifting" thread to join, and then proceed. The problem is

JOptionPane#showMessageDialog(…) does not block on the EDT

五迷三道 提交于 2021-02-11 04:30:36
问题 Upon reading this question, I decided to execute the code that displays a message dialog in my application on the Event Dispatch Thread (EDT). To do this, I modified my method that shows a message dialog from: private static void showMessage(final Component parent, final String message, final String title, final int type) { System.out.println("Before dialog."); JOptionPane.showMessageDialog(parent, message, title, type); System.out.println("After dialog."); } to: private static void

JOptionPane#showMessageDialog(…) does not block on the EDT

大兔子大兔子 提交于 2021-02-11 04:25:22
问题 Upon reading this question, I decided to execute the code that displays a message dialog in my application on the Event Dispatch Thread (EDT). To do this, I modified my method that shows a message dialog from: private static void showMessage(final Component parent, final String message, final String title, final int type) { System.out.println("Before dialog."); JOptionPane.showMessageDialog(parent, message, title, type); System.out.println("After dialog."); } to: private static void

automatic update jtextfield

最后都变了- 提交于 2021-02-05 11:37:55
问题 Does anyone know how to update a jTextfield every 5 secondes? Automatic. So no userinput is required. It is used to update time in a textfield. This is what i tried but then my program freezes. while(true){ Thread.sleep(1000); txtCheck.setText(convert.getCheck()); System.out.println("Ja"); } convert is a thread, i tried to throw an exception but failed, cause Eclise says Threads can't throw exceptions. Convert.getCheck: public String getCheck() { return check; } 回答1: You want to use a Swing

How to get a value from a dialog when on any thread?

核能气质少年 提交于 2021-01-28 02:10:14
问题 I wonder if this is the right way for getting a PIN from a dialog? public static <T> T getFromGui(Supplier<T> supplier) { if (CN.isEdt()) return supplier.get(); final Object[] holder = new Object[1]; CN.callSeriallyAndWait(() -> holder[0] = supplier.get()); @SuppressWarnings("unchecked") final T result = (T) holder[0]; return result; } public static String askPin() { if (!CN.isEdt()) return getFromGui(() -> askPin(bankzugang)); ... final boolean cont = Dialog.show( "Your PIN", BoxLayout

When and Where to call EventQueue.invokeLater() method

淺唱寂寞╮ 提交于 2021-01-21 11:41:32
问题 I'm totally fresh about threading and GUIs, therefore I couldn't figure out exactly where to call this EventQueue.invokeLater() method. Am I supposed to call it in every event listeners and something else? What are those "things" to call this method? If so, is there any alternative way to call-once-apply-everywhere method so that It won't take bunch of lines to tuck them to the Event dispatch thread? Thank you. 回答1: therefore I couldn't figure out exactly where to call this EventQueue

When and Where to call EventQueue.invokeLater() method

a 夏天 提交于 2021-01-21 11:39:07
问题 I'm totally fresh about threading and GUIs, therefore I couldn't figure out exactly where to call this EventQueue.invokeLater() method. Am I supposed to call it in every event listeners and something else? What are those "things" to call this method? If so, is there any alternative way to call-once-apply-everywhere method so that It won't take bunch of lines to tuck them to the Event dispatch thread? Thank you. 回答1: therefore I couldn't figure out exactly where to call this EventQueue

Time Delay using Thread.sleep() for paintComponent(Graphics g) not working as expected

情到浓时终转凉″ 提交于 2020-11-29 02:11:12
问题 I am making an Animated ProgressBar, in which i used multiple fillRect() method of class javax.swing.Graphics . To put a delay after each rectangle is painted, I am using Thread.sleep(500) method for making a delay, (Suggested by many Forums, for making a delay). The Problem is, instead of making a delay of 0.5sec after each Rectangle box is displayed, it takes the whole delay required by all the rectangles, in the start, and then displays the final image, thats the Progress Bar. Question 1