Thanks csfalcon. I implemented your idea of using a timer.
However, the new issue is related to multiline labels with the exact output of the command as you see it in console.
Background info: I'm triggering a system command to display memory utilization. Anyway, as you know, the "free" command displays many lines of text one after the other.
I want to have a label displaying the command output as it is: multiple lines. Just like you see it in the console. I want to mirror whatever comes up on console after executing free from java.
Using html tags won't work out for me in this particular situation. It just doesn't do the trick. Still displays the LAST line of command output *with or without* html tags.
any ideas? it doesn't have to be a label. It can be anything as long as it works.
Code:
//events will trigger every second
Timer t = new Timer(1000, new ActionListener(){
public void actionPerformed(ActionEvent event)
{
//determine memory utilization.
String cmd = "free -m";
try {
String line;
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
label.setText(line);
}
input.close();
}
catch (Exception err) {
err.printStackTrace();
}
}
});
t.start();