event-dispatch-thread

Java Swing - running on EDT

走远了吗. 提交于 2019-12-29 01:33:13
问题 I have a couple of questions with regards to Swing and using EDT for GUI updates. I just started reading on this stuff so I am a full beginner in this area: Which operations are required to run on the EDT? If they don't, is simply an Exception raised? Are there any specific times when we actually are on the EDT automatically? If we schedule a task using SwingUtilities.invokeLater we enqueue it to the current queue of GUI update tasks (the EDT) right? Accesses to the above queue I guess are

Main purpose of SwingUtilities invokeLater

ぐ巨炮叔叔 提交于 2019-12-29 01:32:12
问题 I have this code snippet import javax.swing.SwingUtilities; public class Client1 { public static void main( String[] args ) { SwingUtilities.invokeLater( new Runnable() { public void run() { //new MyWindow( "Bayog" ); new MyWindowV2( "Bayog" ); } } ); } } what is the difference if i will not use SwingUtilities? 回答1: Suppose the code within the run method modifies a UI element. If you try to execute that code from a non-UI thread, it will fail: all UI operations must be performed in the UI

JProgressBar from Oracle

时光毁灭记忆、已成空白 提交于 2019-12-25 19:03:46
问题 I've downloaded a small Java project from oracle website to create a progress bar. I understand it, but I need to apply it in a different way, the application is creating a thread in the background so the progress bar can be updated accordingly ( doInBackground() ). My question is, how can I replace this kind of process in the background in this application by a method from my application (method is just doing a kind of batch processing on a database), can someone help please? Here is code by

Java graphics isn't repainting

半世苍凉 提交于 2019-12-25 07:27:04
问题 I want to add in a feature so that when the mouse goes over a button then it will add a drop shadow. Currently I'm just trying to get the mechanics to work. I have my game loop calling a update method which I know works but here it is anyway public void updateManager(double delta){ mhandler.updateCoordinates(); if(mhandler.getX() >= 144 && mhandler.getX() <= 444 && mhandler.getY() >= 784 && mhandler.getY() <= 980){ oversp = true; }else{ oversp = false; } } mhandler is what I named my

Workaround for non-compliant JVM not sending WindowClosing events

拥有回忆 提交于 2019-12-25 03:08:54
问题 Apple JVM on various OS X version have apparently been broken in that they do not generate the WindowClosing event when they should (for example if you close an app's main JFrame using by clicking on the close button). (in the most recent Apple Java updates you can set a property forcing the event to be generated but this is not what I'm looking for) My problem is simple: I'd like to display a "tip" when the user closes the app. However I cannot (due to the fact that no event is generated)

MultiThreading in java, I want both UI and code to execute in parallel

家住魔仙堡 提交于 2019-12-24 17:42:35
问题 I have a JFrame with progress bar and my code which should run it in background showing the progress in progress bar. I implemented runnable in my Progressbar class and started the thread. But the progress bar frame is not displaying full.. and it gets stuck and it display full after my code is fully executed i.e after main thread close. I know this is some basic mistake. public class ProgressScriptUI extends JFrame implements Runnable{ @Override public void run() { // TODO Auto-generated

MultiThreading in java, I want both UI and code to execute in parallel

穿精又带淫゛_ 提交于 2019-12-24 17:42:12
问题 I have a JFrame with progress bar and my code which should run it in background showing the progress in progress bar. I implemented runnable in my Progressbar class and started the thread. But the progress bar frame is not displaying full.. and it gets stuck and it display full after my code is fully executed i.e after main thread close. I know this is some basic mistake. public class ProgressScriptUI extends JFrame implements Runnable{ @Override public void run() { // TODO Auto-generated

How to replace or restart a deadlocked Swing EventDispatchThread/EventQueue in Java 8 desktop application

只愿长相守 提交于 2019-12-24 14:13:21
问题 A while back we added some code to our application to detect and attempt to recover from a Swing EDT deadlock, so the user could at least save their files (it would be best to not have a deadlock, but...). In Java 1.6, this is easy. Detect that the EDT has been blocked for a sufficient amount of time, and then call this from a background thread: EventQueue newQ = new EventQueue(); Toolkit.getDefaultToolkit().getSystemEventQueue().push(newQ); New UI events will be processed on a new EventQueue

Text Area not getting updated with the button action performed event

☆樱花仙子☆ 提交于 2019-12-24 12:43:44
问题 I have a Text Area swing element where I want to display some execution logs. messages should appear after each execution step. e.g. "Fetching has been started". But the problem is that all logs messages appear only once after the button action performed event is completed.Below is the way I used to display some text getXmlButton = new JButton("Fetch Reports"); getXmlButton.addActionListener((new ActionListener() { @Override public void actionPerformed(ActionEvent e) { createDirectory();

Eclipse/Java: uncaught exceptions on the EDT suspend execution in EventDispatchThread.run()

别说谁变了你拦得住时间么 提交于 2019-12-24 10:41:07
问题 This is a minor annoyance I have when debugging with Eclipse. With "Suspend execution on uncaught exceptions" checked, the debugger will normally suspend a thread right where the exception was thrown. Exceptions on the Event Dispatch Thread, however, cause it to pause on the last line of EventDispatchThread.run(). There is no useful information about what the exception is or what caused it until I resume the thread to allow the stack trace to print to the console. Debug the following code in