event-dispatch-thread

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

故事扮演 提交于 2020-11-29 02:04:17
问题 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

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

这一生的挚爱 提交于 2020-11-29 02:02:03
问题 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

Updating swing components within edt

独自空忆成欢 提交于 2020-06-29 18:49:56
问题 If I understand correctly then when I create GUI swing components, for example I have this: public class frameExample extends JFrame{ public frameExample(){ //Here adding bunch if components setVisible(true); } } So as long as I don't call the setVisible method the components are being made from the thread the instance was created. So if in a class where i have my main method write: JFrame test=new frameExample(); and I sysout Thread.currentThread.getName(); in the constructor in frameExample

ActionListener and Thread.sleep

风格不统一 提交于 2020-03-12 05:44:46
问题 I have a JButton, which, as soon as I click on it, I want to change some colors after a few seconds, for example from blue -> 1 sec -> red -> 1 sec -> yellow. My problem is that, as soon as I use the Thread.sleep function in ActionListener and I test my program, it freezes for the 2 seconds and gives me directly yellow. How can I fix that? Thanks a lot 回答1: ActionListener and Thread.sleep.. ..don't play well together. Don't block the EDT (Event Dispatch Thread) - the GUI will 'freeze' when

ActionListener and Thread.sleep

ぐ巨炮叔叔 提交于 2020-03-12 05:44:27
问题 I have a JButton, which, as soon as I click on it, I want to change some colors after a few seconds, for example from blue -> 1 sec -> red -> 1 sec -> yellow. My problem is that, as soon as I use the Thread.sleep function in ActionListener and I test my program, it freezes for the 2 seconds and gives me directly yellow. How can I fix that? Thanks a lot 回答1: ActionListener and Thread.sleep.. ..don't play well together. Don't block the EDT (Event Dispatch Thread) - the GUI will 'freeze' when

Progress bar not updating during a loop

痴心易碎 提交于 2020-03-06 09:29:10
问题 My progress bar doesn't update until the loop has finished? Why is this? for (String theURL : IPArray) { URL url = new URL(theURL); InetAddress address = InetAddress.getByName(url.getHost()); String temp = address.toString(); String IP = temp.substring(temp.indexOf("/") + 1, temp.length()); URLArray.add(IP); Progress.percentage = (URLArray.size() * 100) / Progress.totalToDo; Progress.ipProgress.setString(Progress.percentage + "%"); Progress.ipProgress.setValue(Progress.percentage); Progress

Progress bar not updating during a loop

一世执手 提交于 2020-03-06 09:28:28
问题 My progress bar doesn't update until the loop has finished? Why is this? for (String theURL : IPArray) { URL url = new URL(theURL); InetAddress address = InetAddress.getByName(url.getHost()); String temp = address.toString(); String IP = temp.substring(temp.indexOf("/") + 1, temp.length()); URLArray.add(IP); Progress.percentage = (URLArray.size() * 100) / Progress.totalToDo; Progress.ipProgress.setString(Progress.percentage + "%"); Progress.ipProgress.setValue(Progress.percentage); Progress

Dispatching events into right thread

六月ゝ 毕业季﹏ 提交于 2020-02-07 07:48:49
问题 I have developed a wrapper for a library that uses a callback to notify events. This callback is called using another thread than UI's thread, so the wrapper uses the following script to call the event handlers into the right thread for a WinForm application. void AoComm::Utiles::Managed::DispatchEvent( Delegate^ ev, Object^ sender, Object^ args ) { ComponentModel::ISynchronizeInvoke^ si; array<Delegate^>^ handlers; if(ev != nullptr) { handlers= ev->GetInvocationList(); for(int i = 0; i <

Sluggish Performance Using JTable Displaying Streaming Data

倖福魔咒の 提交于 2020-01-29 18:41:34
问题 The code I'm referencing is proprietary and requires a multicast server, so I can't post an SSCCE snippet. I understand this may preclude any helpful insight which would elicit viable responses... I'm compiling with Java 7 u 9. I'm currently using a JTable in a GUI app that listens to multicast data, and displays it as it arrives. When scrolling the table or resizing columns, the app responds excruciatingly slow. I thought I structured my code appropriately. I used a wrapper class, and in it

Sluggish Performance Using JTable Displaying Streaming Data

荒凉一梦 提交于 2020-01-29 18:40:13
问题 The code I'm referencing is proprietary and requires a multicast server, so I can't post an SSCCE snippet. I understand this may preclude any helpful insight which would elicit viable responses... I'm compiling with Java 7 u 9. I'm currently using a JTable in a GUI app that listens to multicast data, and displays it as it arrives. When scrolling the table or resizing columns, the app responds excruciatingly slow. I thought I structured my code appropriately. I used a wrapper class, and in it