jprogressbar

Can't update value of JProgressBar from another thread when adding another items

风格不统一 提交于 2019-12-08 13:43:31
问题 I have a problem with displaying current status(in JProgressBar) while adding another components to JPanel. This operation is heavy and takes at about 2 seconds with 20 iterations (adding 20 items). But it can be 100 items. So I need to achieve displaying current status of every iteration in JProgressBar, but I can't realize how to do it. (In my code it is value perc ) And can you explain how EDT works? Is it adding events into queue to the end? Thank you! My JProgressBar object:

Connect JProgressBar with download process

亡梦爱人 提交于 2019-12-08 09:06:57
问题 I have the below code. I can't make it work. I have to mention that the URL is redirecting. I mean that url = http://www.thissite.com and redirects to http://www.othersite.com . But I want to get it work with the initial url . public void download(String address, String localFileName, JProgressBar progress ) { OutputStream out = null; URLConnection conn = null; InputStream in = null; try { URL url = new URL(address); // Open an output stream to the destination file on our local filesystem out

Custom Painter on JProgressBar

前提是你 提交于 2019-12-07 07:17:44
问题 I'm attempting to change the colour of Progress Bars in my current Swing L&F (I'm using Nimbus at the moment) by using a custom Painter object, but when created these Progress Bars sometimes stick with their original colouring (this change seems to occur randomly). I'm probably missing something simple but I'm stumped, Painter object (and it's invocation below)... import javax.swing.Painter; import java.awt.*; public class ProgressPainter implements Painter { private Color light, dark;

Progress bar while copying files with Java

佐手、 提交于 2019-12-06 18:26:17
问题 I'm sure this question has been asked before, but none of the answers I found will work very well with my existing code. I'm posting this question in case there's a way to do it without completely redoing what I have so far. The idea is to display a very basic progress bar while copying files and directories from one drive to another. I have a class called BasicCopy that is designed to copy the contents of the Pictures, Documents, videos, and Music folders (standard on Windows machines) to

Update JProgressBar from new Thread

北城余情 提交于 2019-12-06 10:38:27
How can I update the JProgressBar.setValue(int) from another thread? My secondary goal is do it in the least amount of classes possible. Here is the code I have right now: // Part of the main class.... pp.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent event){ new Thread(new Task(sd.getValue())).start(); } }); public class Task implements Runnable { int val; public Task(int value){ this.val = value; } @Override public void run() { for (int i = 0; i <= value; i++){ // Progressively increment variable i pbar.setValue(i); // Set value pbar.repaint(); // Refresh

Java JProgressBar using Image

喜你入骨 提交于 2019-12-06 07:14:10
问题 I am making a game in Java, and I am using a JProgressBar for a health bar. I want to use an image (instead of colours) for the JProgressBar , but I have not been able to do it. I have tried using the paint method, paintComponent method, making a new class, but it's not working. May someone please help me? 回答1: Without going to the extent to creating your own ProgressBarUI implementation, you could simply create your own... This example essentially makes a "bar of potions" out of a single

JFrame freezes during while loop [duplicate]

佐手、 提交于 2019-12-06 07:13:55
This question already has answers here : Running a JFrame with a JProgressBar (2 answers) Closed 6 years ago . I am working on a Java program, which reads text files does some probability calculations. Reading files and all related calculations are done in a while loop. I had created a GUI using JFrame, where i had added a Progress bar (using JProgressBar) to show the progress since the program takes a while to process the files. The code looks like - while( there are more files to read ) { Read this file ; Do calculations ; Update progress bar ; } Now, the problem is once the while loop

How do I use JProgressBar to display file copy progress?

偶尔善良 提交于 2019-12-06 06:24:56
问题 I am working on a project that transfers files over a network and I want to incorporate a JProgressBar to show the progress during file transfer but I need help on that. 回答1: You probably would find a ProgressMonitorInputStream easiest, but if that doesn't do enough for you, look at its source code to get exactly what you want. InputStream in = new BufferedInputStream( new ProgressMonitorInputStream( parentComponent, "Reading " + fileName, new FileInputStream(fileName) ) ); To use a different

JProgressBar Changing Bar Color dynamically

有些话、适合烂在心里 提交于 2019-12-06 02:34:11
问题 I am using JProgressBar component along with the Nimbus UI Defaults. The problem is that When I want to manually change each progressbar's Bar color, I use BasicProgressBarUI by setting JProgressBar.setUI() function. This makes more trouble because I would like to just change the bar color and it seems that I loose the default look of the jprogressbar (Border, backgroundcolor dissappears). So I can set UIDefaults of Nimbus ProgressBar when the code initializes. It works. But I want to change

How to use JProgressBar

╄→尐↘猪︶ㄣ 提交于 2019-12-05 20:35:57
I want to use JProgressBar and it must be loaded in one second. I don't want wait for any task to complete. Just want to fill the progress bar in one second. So I write following code. But it doesn't working. progress bar wasn't filling. I am new to Java. Please can anyone help me. public void viewBar() { progressbar.setStringPainted(true); progressbar.setValue(0); for(int i = 0; i <= 100; i++) { progressbar.setValue(i); try { Thread.sleep(10); } catch (InterruptedException ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } } progressbar.setValue(progressbar.getMinimum()); } You can