Question

I'm new to Java, so I would ask you not to write the code too complicate, or just describe what the code means.

Let me explain what I want:

I've made a Java GUI with an "Install"-Button. The function of this button is, to extract a Zip File to a specific folder.

public void mouseClicked(MouseEvent event) {
    if (event.getSource() == button_normal) {
        button_normal.setPressedIcon(button_hover_img);
        try {
            unzip();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

So this method just calls the unzip Method.

Now I want, that the extracted files are displayed within a text area. If the text is too long, the box should add a scroll button at it sides.

message_output.setText(message);

When I set this code within the unzip Method, it will just write the string (which contains the extract path of all file) after the program extracted all the files. Additionaly it doesn't add the scroll buttons at the sides, if the text is too long.

How I can add the text 1 by 1 to the text area, while extracting the files?

Thanks

So Far

Was it helpful?

Solution

How I can add the text 1 by 1 to the text area, while extracting the files?

You need to create a separate Thread to do the file extraction. Then as you start to extract each file you update the GUI.

The easiest way to do this is to use a SwingWorker since you can "publish" each file as it is about to be extracted.

Read the section from the Swing tutorial on Concurrency for more information and an example of a SwingWorker.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top