swingworker

JButton ActionListener - GUI updates only after JButton is clicked

大城市里の小女人 提交于 2019-11-26 17:51:52
I'm having a problem with my JButton ActionListener. I have a doTheCleaning() method defined in another class which when called makes series of changes to my GUI. public void doTheCleaning(){ //change image icon //had thread.sleep here //insert to text area //had thread.sleep here //etc } Then in another class, I instantiated the class containing my doTheCleaning() method and had my ActionListener written with my actionperformed() method for my jbutton written like this: public void actionPerformed(ActionEvent e){ //some code //newClass.doTheCleaning(); } I know how to do the rest like

JComponents disappearing after calling mouseClicked()

喜夏-厌秋 提交于 2019-11-26 17:29:17
问题 I am writing a Java GUI program with Swing. The interface looks like this: When the user clicks on one of the pictures on the right hand side, I want a small preview of it to show up in the orange area in the upper left corner. I pull all of the image files from a directory on my computer via a SwingWorker thread. In the SwingWorker's done() method, I add a mouseClicked listener to each object (a TaggableImage object from a class I created. It has a BufferedImage and extends JComponent,

Populate JTable with large number of rows

我的未来我决定 提交于 2019-11-26 16:42:50
I would like to populate a JTable during runtime with many rows (lets say 10000). But all my attempts are very poor and inefficient. Starting point is the addData method which gets a List of Objects representing a row. I tried to fill the table via a SwingWorker but this only works for small data for me. Another attempt was setting the data directly without using any kind of thread, but this is also very slow, at least the UI isn't blocked like its the case with the SwingWorker. So how do you do this is general? The table should be filled row by row or chunkwise but not all by one and the

Swing Worker : function get()

放肆的年华 提交于 2019-11-26 16:41:48
My problem is that I don't understand how the swingworker works because what I'm trying to do is to make fa=worker.get() because I have a long method which compute a lot of points running in background because I don't want to freeze my interface and I want to get her results to paint the component image. But I don't understand where it goes when I do fa=worker.get() because my console prints "titi" and I put a lot of other printing to see the next part of program reached but no one is printed. Please help me to know where the compilation goes after get() or while it execute it and if you have

Issues with SwingWorker and JProgressBar

老子叫甜甜 提交于 2019-11-26 15:31:48
I need to convert a any image given to a byte array for encryption requirement. I'm using JProgressBar to monitor the conversion progress in case the chosen image is large: File p= new File("C:\"); BufferedImage oImg = ImageIO.read(p); ByteArrayOutputStream ba = new ByteArrayOutputStream(); ImageIO.write(oImg, "jpg", ba); ba.flush(); ProgressBar pb = new ProgressBar(); Thread thread = new Thread(pb); thread.join(); pb.fireTask(ba.toByteArray()); I defined a ProgressBar class that uses SwingWorker as follows: public class ProgressBar extends JPanel implements Runnable { private JProgressBar

How to use SwingWorker?

若如初见. 提交于 2019-11-26 14:53:53
问题 Friends, i am developing a java application. Thats for performance monitoring. on that i am getting values in one class and drawing a graph in another class. i want to use swingworker to perform those two class alternatively. ResultSet rs; Connection conn = null; conn = (Connection)getMySqlConnection(); Statement st = conn.createStatement(); rs = st.executeQuery("SHOW GLOBAL STATUS"); while(rs.next()) { Map_MySql.put(rs.getString(1), rs.getString(2)); } conn.close(); Above class for

Can't get JProgressBar to update from SwingWorker class

六眼飞鱼酱① 提交于 2019-11-26 14:51:47
问题 I have my main GUI thread which has a JprogressBar in it and is implementing ProprtyChangeListener. When a button is pressed, a different class, which extends SwingWorker, kicks into action and performs a series of potentially long calculations. I need the progress bar in class A to present the progress according to a variable in Class B. My code is below (could be a bit messy with all my failed tries...) Would appreciate any help. GUI CLASS: SignalSimulator signalSimulator = new

Stop/cancel SwingWorker thread?

被刻印的时光 ゝ 提交于 2019-11-26 14:41:20
问题 I'm trying to find out how to stop a SwingWorker thread from running when I press a button. I have been looking around and I'm having some trouble working out how to do this. At the moment this is what I have: new MySwingWorkerClass(args).execute(); I'm then creating a button which I want to use in order to stop the thread: button = new JButton("Stop"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // Stop the swing worker thread } }); I have

How do I make my SwingWorker example work properly?

匆匆过客 提交于 2019-11-26 13:46:45
I've made my own SwingWorker example to get familiar with how it works. What I'm wanting to do is the following: When the button is clicked I want a progress bar appear until the task is done I want to simply remove the progress bar and add a string to the dialog. When the button is clicked, the progress bar comes up but never goes away. (never removes the progress bar after 10 seconds and never places the label up) Here is an SSCCE: package swingtesting; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JDialog; import

How do I simulate a buffered peripheral device with SwingWorker?

一个人想着一个人 提交于 2019-11-26 11:56:11
I'm using this exercise as a pedagogical tool to help me burn in some Java GUI programming concepts. What I'm looking for is a general understanding, rather than a detailed solution to one specific problem. I expect that coding this "right" will teach me a lot about how to approach future multi-threaded problems. If this is too general for this forum, possibly it belongs in Programmers? I'm simulating a card reader. It has a GUI, allowing us to load cards into the hopper and press Start and so forth, but its main "client" is the CPU, running on a separate thread and requesting cards. The card