I have a Java program that's using ProcessBuilder
to set up some Servers.
I have also made a Form
, that displays a JProgressBar
, a JLabel
and a JTextArea
. The Progressbar is set to be indeterminate, since there doesn't seem to be a way for easy calculation of the workload.
The Label is regularly updated to show the User at which step the programm currently is, and the TextArea displays extra information about the current step.
However, when I start the setup, the Window opens and displays nothing. Just a blank white window with a title. That is until the setup is either done, or when I'm debugging, where it will sometimes actually display something for a short time.
I have tried calling panel.revalidate() together with panel.repaint() everytime I update a property, but this hasn't changed anything. I remember faintly that there's a specific way to update components while the program is doing stuff in the background, but cannot remember how, and wasn't able to find anything helpful so far.
public void shutdownSystems() throws IOException, InterruptedException {
for (String ip : ipArray) {
if (isWindows) builder.command(ipmitool, ip, "ADMIN", "ADMIN", "ipmi", "power", "down");
loadingForm.setProgressInfo("Shutting down System " + ip);
startProcess();
loadingForm.setProgressInfo(streamGobbler.getResult());
refreshLoadingWindow();
}
}
Here's a piece of code to showcase how I'm trying to do it currently. loadingForm
refers to the window which is supposed to have it's components updated. startProcess();
is a local method that executes the command set by the ProcessBuilder builder
and compiles the output to also add this information to the window. Last but not least, I call refreshLoadingWindow();
which basically just gets the panel of loadingForm
and executes .revalidate();
and .repaint();
The main thing that is confusing me is, while I understand that there's probably a different approach to updating GUIs, it doesn't even show the components at all. Not even when first opening the window.
Can anyone tell me what I'm supposed to be doing instead?