swingworker

Implementing JScrollPane/JTextArea in SwingWorker

﹥>﹥吖頭↗ 提交于 2019-12-12 01:05:22
问题 I am having some trouble with my JScrollPane/JTextArea when using a SwingWorker. Here is what I currently have: JTextArea txtDirs; Task task; //EDT public void createGUI(){ txtDirs = new JTextArea(); txtDirs.setBounds(10, 56, 414, 125); txtDirs.setEditable(false); contentPane.add(new JScrollPane(txtDirs)); task = new Task(); task.execute(); } class Task extends SwingWorker<Void, Void>{ @Override public void doInBackground(){ for(file : files){ txtDirs.append(file.getAbsolutePath); } }

SwingWorker : illegal start of type

孤者浪人 提交于 2019-12-11 23:57:21
问题 it is a piece of code that caused my problem : SwingWorker <Vector,void> sw=new SwingWorker <Vector,void>(){ @Override protected Vector doInBackground() throws Exception { TvaJpaController tjc =new TvaJpaController(emf); Vector l_tva=null; try{ l_tva= (Vector) tjc.findTvaEntities(); } catch(javax.persistence.PersistenceException e) { javax.swing.JOptionPane.showMessageDialog(null,"please check your internet connecting"); } return l_tva; } @Override protected void done() { Vector l_tva=null;

SwingWorker - Same variable shows different values on sysout and GUI

时间秒杀一切 提交于 2019-12-11 21:23:57
问题 Edit: Note, this question is related to my other question here: SwingWorker - Passing parameters and returning an ArrayList<Object> After digging around SwingWorker and in order to try to solve that question I came up with this SSCCE code. End of Note End of edit Given the following SSCCE code: import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java

jTable populating and refreshing ArrayIndexOutOfBoundsException

故事扮演 提交于 2019-12-11 20:23:58
问题 I have below SwingWorker for populate the jTable1. And i have button for executing this task. public class WorkerTime extends SwingWorker<Void, Void> { protected Void doInBackground() throws Exception { DefaultTableModel model1 = (DefaultTableModel) jTable1.getModel(); model1.setRowCount(0); for (int i = 0; i < 5; i++){ model1.addRow(new String[]{"a","a","a","a","a","a","a","a","a","a","a"}); model1.fireTableDataChanged(); } return null; } public void done() { } } First, second and sometimes

how to pass textfield from main class to another class

≯℡__Kan透↙ 提交于 2019-12-11 19:19:49
问题 How to pass the textfield from main class pri to CounterTask1 class. Below program is an example. Real program contains similar construction. In CounterTask1 class the textfield add with another string.If click print button it should print textfield in terminal. Advance Thanks. import java.io.*; import javax.swing.*; import java.awt.event.*; import javax.swing.SwingWorker; import java.util.List; public class pri { JFrame Frame1 = new JFrame(); JLabel SourceLabel1 = new JLabel("Source Name");

java - thread.sleep() within SwingWorker

元气小坏坏 提交于 2019-12-11 17:34:21
问题 I am just wondering if the following code is correct. I have a SwingWorker that does something, sleeps, does something else and updates GUI. Is it okay to use Thread.sleep inside SwingWorker? class MySwingy extends SwingWorker<Void, Void> { @Override public Void doInBackground() { //Do Something try { Thread.sleep(200); } catch (Exception ex) { } //Do Something } @Override public void done() { //Update GUI } } 回答1: If you really need to, there is no technical reason why you can't do that. The

SwingWorker gui repaint

你。 提交于 2019-12-11 13:52:52
问题 Im trying to use the SwingWorker to update my gui without calling repaint(). I want the SwigWorker to update the status of each GridGraphic[i][j] and the have the gui be repsonsive to the changes without calling repaint(). GridGraphic.java import java.awt.*; import javax.swing.*; public class GridGraphic extends JComponent { private int intensity = 0; public GridGraphic() { //setBorder(BorderFactory.createLineBorder(Color.BLUE)); } public void paintComponent(Graphics g) { //paints the

Java Swingworker Thread

廉价感情. 提交于 2019-12-11 13:16:20
问题 I have a question to ask about Java Concurrency. I'm practicing Java Threading. What i do is create a simple interface which has a button and a JSlider. So when i click the button a variable will increase and the JSlider moving accordingly. Now I wonder if Swingworker is a right choice. 回答1: You only need to use SwingWorker for long-running tasks. What you describe will be performed instantly. Therefore you can do this on the Event Dispatch Thread, where all ActionListeners are performed. 回答2

Java SwingWorker - using publish/process to update a TextArea in EDT?

╄→尐↘猪︶ㄣ 提交于 2019-12-11 06:53:39
问题 I had just coded a Swing program that starts up a SwingWorker (which runs a Socket Server). I have a JTextArea on the Swing GUI which gets updated with the data received by the Socket Server, using a JTextArea.append(String). Is it the correct/threadsafe way to update a JTextArea on the Swing GUI? What about using publish/process? 回答1: SwingWorker is usually used for one time long running processes (anything that will take more than a few milliseconds to complete). If you have persistent

How can I make a Progress Bar class that's value can be Updated from the calling class

别等时光非礼了梦想. 提交于 2019-12-11 05:53:27
问题 I have tried following tutorials but I keep getting lost somewhere. What I need is a class that creates and displays a progress bar ( JProgressBar ) that I can set the value of as I iterate over data loaded from a file and place into the database memory. My problems come that every example I have found has some kind of counter that fills the progress bar and executes from a "main" function. Every time I alter that tutorial to be a class that I can call at will and display the bar, I do not