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

  • Home
  • SEARCH
  • 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 968775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:32:15+00:00 2026-05-16T02:32:15+00:00

**Hello, I’m trying to create an archiver in java. This means that I am

  • 0

**Hello, I’m trying to create an archiver in java. This means that I am constantly reading and writing from streams. I want to be able to update a JProgressBar to show how much I have written. My code currently updates the progress bar after each entry in the archive. My variables and everything say that the code is updated, except its not showing on the screen. After each entry into the archive I call the revalidate() method on the JPanel that contains the progress bar and text, but nothing happens on the screen. The screen doesn’t update until the output stream that is writing the archive has completely finished writing. Then, I see the full progress bar with “24 out of 24 files written” in the progress text.

Can anyone tell me how I can get the graphics to update before my code finished executing? Thanx

Here is my code:

WritingBox.java:

package org.apache.commons.compress;
import javax.swing.JDialog;
public class WritingBox extends javax.swing.JDialog {

/** Creates new form WritingBox */
public WritingBox(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    theprogressbar.setMaximum(1);
    theprogressbar.setMinimum(0);
    this.setLocation(parent.getLocationOnScreen().x+(parent.getWidth()-this.getWidth())/2, parent.getLocationOnScreen().y+(parent.getHeight()-this.getHeight())/2);
    this.setVisible(true);
}
public void progressListener(Progress p) {
    writtenxoutofx.setText("Written "+Integer.toString(p.doneSoFar)+" out of "+Integer.toString(p.total)+" files to the Archive");
    theprogressbar.setValue(p.doneSoFar/p.total);
    if (p.doneSoFar == p.total) this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    thecontainer.revalidate();
};
/** This method is called from within the constructor to
 * initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

    thecontainer = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    writtenxoutofx = new javax.swing.JLabel();
    theprogressbar = new javax.swing.JProgressBar();

    setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
    setName("Form"); // NOI18N

    thecontainer.setName("thecontainer"); // NOI18N

    org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(targzipmanager.TarGzipManagerApp.class).getContext().getResourceMap(WritingBox.class);
    jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
    jLabel1.setName("jLabel1"); // NOI18N

    writtenxoutofx.setText(resourceMap.getString("writtenxoutofx.text")); // NOI18N
    writtenxoutofx.setName("writtenxoutofx"); // NOI18N

    theprogressbar.setName("theprogressbar"); // NOI18N

    javax.swing.GroupLayout thecontainerLayout = new javax.swing.GroupLayout(thecontainer);
    thecontainer.setLayout(thecontainerLayout);
    thecontainerLayout.setHorizontalGroup(
        thecontainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(thecontainerLayout.createSequentialGroup()
            .addContainerGap()
            .addGroup(thecontainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(theprogressbar, javax.swing.GroupLayout.DEFAULT_SIZE, 307, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addComponent(writtenxoutofx))
            .addContainerGap())
    );
    thecontainerLayout.setVerticalGroup(
        thecontainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(thecontainerLayout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jLabel1)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(writtenxoutofx)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(theprogressbar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(thecontainer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(thecontainer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );

    pack();
}// </editor-fold>

// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel thecontainer;
private javax.swing.JProgressBar theprogressbar;
private javax.swing.JLabel writtenxoutofx;
// End of variables declaration

}

Progress.java

package org.apache.commons.compress;

public class Progress { //This is basically a Struct
public int total;
public int doneSoFar;
private Progress (){

}
public Progress(int d, int t){
    total = t;
    doneSoFar = t;
}
}

TarArchive.java: doSave method

public void doSave(OutputStream output) throws ArchiveException {
        // Stream initializing
        //BufferedInputStream origin = null;

        //out.setMethod(ZipOutputStream.DEFLATED);
        //byte data[] = new byte[BUFFER];

        // get a list of files from current directory
        // less than one file leads to an exception
        Iterator iterator = this.getEntryIterator();
        if(!iterator.hasNext()) {
              throw new ArchiveException("There must be at least one file to be pack.");
        }
        JFrame jf = targzipmanager.TarGzipManagerApp.getApplication().getMainFrame();
        WritingBox wb = new WritingBox(jf, false);
        TarOutputStream out = null;
        int x = 0;
        try {
              out = new TarOutputStream(new BufferedOutputStream(output));
              while(iterator.hasNext()) {
                    x++;
                    ArchiveEntry archiveEntry = (ArchiveEntry)iterator.next();
                    InputStream fInputStream = archiveEntry.getStream();

                    TarEntry entry = new TarEntry(archiveEntry.getName());
                    entry.setModTime( 0 );
                entry.setSize( fInputStream.available() );
                entry.setUserID( 0 );
                entry.setGroupID( 0 );
                entry.setUserName( "avalon" );
                entry.setGroupName( "excalibur" );
                entry.setMode( 0100000 );
                out.putNextEntry( entry );
                out.copyEntryContents( fInputStream );
                out.closeEntry();
                wb.progressListener(new Progress(x, entries.size()));
              }
        } catch (IOException e) {
              throw new ArchiveException("Creation of this archive failed cause of IOExceptions.", e);
        } finally {
              try {
                    out.close();
              } catch (IOException e1) {
                    throw new ArchiveException("Creation of this archive failed cause of IOExceptions.", e1);
              }
        }
  }

Can anyone help me? Even though I’m calling revalidate() after each entry, it only updates when the code stops and it starts waiting. **

  • 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-05-16T02:32:16+00:00Added an answer on May 16, 2026 at 2:32 am

    Sounds like you are doing the file I/O on the AWT Event Dispatch Thread (EDT). This blocks any repaints or event handling. Run the I/O on a different thread, and update the GUI through java.awt.EventQueue.invokeLater.

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

Sidebar

Ask A Question

Stats

  • Questions 485k
  • Answers 485k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The solution was rather simple, after all. Since I was… May 16, 2026 at 7:48 am
  • Editorial Team
    Editorial Team added an answer Carriage return, line feed - on Windows? It would help… May 16, 2026 at 7:48 am
  • Editorial Team
    Editorial Team added an answer Because there is a implicit return None at the end… May 16, 2026 at 7:48 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.