event-dispatch-thread

What is the ways updating jProgressBar?

你。 提交于 2020-01-05 04:43:14
问题 I need to update jProgressBar in method which read from file and do some operations. I tried to update progress bar by this method: public void progressUpdate(int percent) { System.out.println("Update = "+percent); synchronized (jMainProgressBar) { jMainProgressBar.setValue(percent); } SwingUtilities.invokeLater( new Runnable() { public void run() { jMainProgressBar.updateUI(); jMainProgressBar.repaint(); } }); } how ever this works only then when method is done. But if i continuously

Displaying a loading JFrame while a loop is running in main thread

[亡魂溺海] 提交于 2020-01-04 09:13:08
问题 this is my first post so please inform me if I'm doing anything wrong. I've been working on a mini-applet to get the status of several nodes. This works by having a thread of each node which checks its uptime in a network class. Once it gets the status of the node it'll put it into a hashmap. I then check the status of that hashmap and wait till its content amount is equal to the total amount of nodes that we're checking. Once done it proceeds to display them on a screen. The problem is

Displaying a loading JFrame while a loop is running in main thread

折月煮酒 提交于 2020-01-04 09:12:34
问题 this is my first post so please inform me if I'm doing anything wrong. I've been working on a mini-applet to get the status of several nodes. This works by having a thread of each node which checks its uptime in a network class. Once it gets the status of the node it'll put it into a hashmap. I then check the status of that hashmap and wait till its content amount is equal to the total amount of nodes that we're checking. Once done it proceeds to display them on a screen. The problem is

When is the Swing UI thread created?

女生的网名这么多〃 提交于 2020-01-04 02:44:26
问题 When, in the process of running a Swing program, is the UI thread (event-dispatch thread, EDT) first spawned? Presumably any given JVM could do whatever it wants (for example, always spawning the EDT at start-up, whether or not it's ever used), but as a practical matter when is the EDT typically created? Does it get created when SwingUtilities.invokeLater() is first called? When a JPanel is first instantiated? And if the event pump is started separately from creating the EDT, when does that

Creating an Event Dispatch Thread safe semaphore

ⅰ亾dé卋堺 提交于 2020-01-04 00:23:32
问题 I've been trying to make a binary semaphore that will be able to safely block execution of a method running on the event dispatch thread (EDT) without actually blocking the thread from handling more events. This may initially seem impossible, but Java has some built-in functionality related to this, but I can't quite get it to work. Use Case Currently, if you show a modal swing dialog from the EDT, it will appear to block the EDT (because your method that displayed the modal dialog will not

How to prompt a confirmation dialog box in the middle of non event dispatching thread

痴心易碎 提交于 2020-01-03 14:40:31
问题 I have the following fun which will be executed by non event dispatching thread. In the middle of thread, I want a A confirmation box pop up. Thread suspend its execution. User makes a choice. Thread will get the choice and continue execution. However, I find out it is not easy to do it in thread safety way, as dialog box should be shown by event dispatching thread. I try public int fun() { // The following code will be executed by non event dispatching thread. final int choice;

Multiple Event Dispatch Threads

∥☆過路亽.° 提交于 2020-01-02 03:43:06
问题 I am new to Java Swing and my question is related to Event Queues and Dispatch threads. I read that it is possible to have multiple event queues , each per AppContext instance. Similarly does it mean each AppContext Event queue has its own event dispatch thread. 回答1: It is only possible to have one event dispatch thread as far as I'm aware. Apparently AppContext is not meant to be used by developers, although I'm not really familiar with it. 回答2: 1) basically you only needed to know if your

Java Swing heavy/slow paintComponent - any advice?

懵懂的女人 提交于 2019-12-31 04:10:59
问题 I'm making a scrolling 2D map/tile based game. Each tile (stored as tile[21][11] - 231 tiles total per map) can contain up to 21 values (stored as int[3][7]). While full-screen I see about 8 maps at once. On average, each map takes about 0.03 seconds to draw (found with System.nanoTime). The problem is that as soon as more than 1 map is on the screen, the Swing event polling noticeably slows down. Is there any solution to this? I can't draw the map a single time to save it as an image because

How to stop repaint() flickering

China☆狼群 提交于 2019-12-29 09:30:11
问题 I am trying to make a program to java and i have the common problem with flickering. I have try many things to eliminate but all the same. while the oval that i paint is moving the japplet is flickering. i need your help to solve this problem. here is my code: import java.awt.Color; public class all extends JApplet implements Runnable { double x=0; double y=0; int m=0; int n=0; int f=30; int μ=0; Thread kinisi; JPanel panel; JFrame frame; private boolean running = false; private JTextField

Thread sleep inside of actionPerformed method

£可爱£侵袭症+ 提交于 2019-12-29 08:55:12
问题 First of all I want to say I'm aware this aproach is wrong so I'm asking this question because of pure curiousity. Lets say I have a swing application like this: import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingUtilities; public class ThreadSleeping { JFrame frame = new JFrame();