Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7986059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:44:18+00:00 2026-06-04T11:44:18+00:00

I would like to show progress bar in my swing app, which will zip

  • 0

I would like to show progress bar in my swing app, which will zip the selected file.
for this process i want to show a progress bar while processing.It may be in a JOptionPane or a given panel as a parameter to utility.

//Select a text file to be zip    
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("."));


chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
  public boolean accept(File f) {
    return f.getName().toLowerCase().endsWith(".txt")
        || f.isDirectory();
  }

  public String getDescription() {
    return "GIF Images";
  }
});

String source ="";
int r = chooser.showOpenDialog(new JFrame());
if (r == JFileChooser.APPROVE_OPTION) {
   source = chooser.getSelectedFile().getPath();
  File file = chooser.getSelectedFile();

//Start ZIP
try {

        String target = "upload/data-1.zip";
        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(target));
        FileInputStream fis = new FileInputStream(file);

        // put a new ZipEntry in the ZipOutputStream
        zos.putNextEntry(new ZipEntry(file.getName()));

        int size = 0;
        byte[] buffer = new byte[1024];
        JProgressBar pb = new JProgressBar();
        pb.setStringPainted(true);
        pb.setIndeterminate(true);

        JPanel panel = new JPanel();
        panel.add(pb);
        JOptionPane.showInputDialog(panel);



        // read data to the end of the source file and write it to the zip
        // output stream.
        while ((size = fis.read(buffer, 0, buffer.length)) > 0) {
                zos.write(buffer, 0, size);
               pb.setValue(size);
               pb.repaint();
               if (size >= file.size) {
                 panel.dispose();
               }
            <<HERE I TRIED TO GIVE PROGRESS ABR VALUE BUT NOT SUCCEDED>>
        }

        zos.closeEntry();
        fis.close();

        // Finish zip process
        zos.close();
        System.out.println("finished");
} catch (IOException e) {
        e.printStackTrace();
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:44:19+00:00Added an answer on June 4, 2026 at 11:44 am

    Consider using SwingWorker. You can update UI with intermediate results using process() method. Also, SwingWorker has bound progress property. You can use setProgress() to update it. Then, add PropertyChangeListener to respond to progress property updates.

    Check out How to Use Progress Bars. The article demonstrates collaboration of SwingWorker with a progress bar.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to show a progress bar indicating how much of a file
I would like to show a progress view while my app is downloading files
I would like to show a progress bar/loading popup in a web page until
I am loading a file and would like to show the progress in a
i'd like to show a progress bar while i update the app with fresh
I would like to show a modal progress wheel overlay on my view. The
I would like to show the bottom application bar based on a button. Is
I found this great post on creating a progress bar with javascript: Show javascript
Actually, I would like to have some kind of progress bar. I would like
I am reading data from a file and would like to attach a progress

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.