jprogressbar

Using SwingWorker to update the progress of a thread from another class

ぃ、小莉子 提交于 2020-01-14 05:27:50
问题 Value is updated by the end, but not during the process. I guess the reason is that the publish method locates outside the loop. As to invoke PropertyChangeListener , can it be achieved by defining the class without extends SwingWorker<Void, Void> ? To address the question in another way, I have two threads locate in two different classes. Is it possible to build communication between the two using SwingWorker ? Class Application import javax.swing.JFrame; public class Application { public

How do I track reading of a a file using .readLine() in java?

旧巷老猫 提交于 2020-01-07 04:54:50
问题 I am reading a file using bufferedREader ,the file is a text file with lot of text here is how I am reading it while(true) //I know the loop is not perfect just ignore it for now, i wanna concentrate on the tracking { try { br.readLine(); } catch(IOException e) { break; } catch (Exception e) { break; } } I want to track what percentage of the file I have read so I can use that percentage value in my progress bar like this: while(true) { try { br.readLine(); progressBar.setValue(percentageRead

How to run method with JProgressBar

可紊 提交于 2020-01-06 04:45:30
问题 I have a function called CreateAccount . I need it to run and also need to show a progress bar. When I click the button, the method will start. And I need to start showing loading progress bar. Once method is done progress bar also should stop at 100. If the method gets more time to do the job, progress bar also needs to load slowly. I tried using following code but it is not synchronizing progress bar with the method. So how can I do that? Here is my code: private static int t = 0; private

How to update a progress bar from a method inside SwingWorker

前提是你 提交于 2020-01-05 12:31:34
问题 I'm trying to update a progress bar and I can't do it. My code is something like this: public class MyWorker extends SwingWorker<Void, Void> { public Void doInBackground(){ howMany=Integer.parseInt(textField.getText()); String result=longMethod(howMany); label.setText("Hello, you have "+result); } } public class Event implements ActionListener{ public void actionPerformed(ActionEvent e){ label2.setText("Whatever"); button.setEnabled(false); myWorer.addPropertyChangeListener(this); myWorker

How to update a progress bar from a method inside SwingWorker

北慕城南 提交于 2020-01-05 12:29:05
问题 I'm trying to update a progress bar and I can't do it. My code is something like this: public class MyWorker extends SwingWorker<Void, Void> { public Void doInBackground(){ howMany=Integer.parseInt(textField.getText()); String result=longMethod(howMany); label.setText("Hello, you have "+result); } } public class Event implements ActionListener{ public void actionPerformed(ActionEvent e){ label2.setText("Whatever"); button.setEnabled(false); myWorer.addPropertyChangeListener(this); myWorker

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

JProgressBar in JTable problem

纵然是瞬间 提交于 2020-01-04 06:35:35
问题 I've got some problem, does anyone can help me ? Below is my code: public class Test { public static void main(String[] args) { Panel.panel.setVisible(true); } } class Panel extends JFrame implements Runnable { public static Panel panel = new Panel(); JButton b= new JButton("Start"); public Panel() { setLayout(new FlowLayout()); setSize(300,300); add(b); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { javax.swing.SwingUtilities.invokeLater(new Runnable(

How can I set up my JProgressbar to show the progress of my program loading

江枫思渺然 提交于 2019-12-31 07:47:06
问题 When my program starts, my JProgressBar runs just like I want it and shows the progress of my program loading, but I have a restart function for the database and I have to use the dispose() to reset all the components and thus reloading all the components. The restart process is exactly the same as startup, but in this instance the JProgressbar Doesn't load at all(Just a blank window), the whole class doesn't want to work. a run through the below code: the If statement tests if the database

how to include a progress bar in a program of file transfer using sockets in java

牧云@^-^@ 提交于 2019-12-29 02:08:16
问题 i am working on a project in java that transfers files from a client to a server. now i need to show the progress bar for each file transfer i.e the progress bar should automatically pop up as each transfer starts. i have made the program to create a progress bar but i am not able to merge it with the client-server programs. i would really appreciate if someone helps me with the loop to be used. thank you. ClientMain.java public class ClientMain { private DirectoryTxr transmitter = null;

JButton Action Listener progress bar, update without freezing?

。_饼干妹妹 提交于 2019-12-25 19:08:59
问题 I've got a progress bar, when I strike the button, on the button listener I've got a progress bar that updates as something downloads. However, the GUI freezes until the download is complete. How can I get this progress bar to update as the download continues? However, if the download starts when the application is compiled without user interference, the download progresses as the progress bar updates. However, it's the complete opposite on JButton action listener. How can I use SwingWorker