Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to? multiline label containing exact system command output  RSS feed

 
Benjamin Mulder
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Background info: I'm triggering a system command to display memory utilization. "free" is a unix command but you can use "mem" on Window$ console. Same functionality.

Anyway, as you know, the "free" (unix) or "mem" (window$) displays many lines of text one after another.

I want to have a label displaying the command output as it is: multiple lines. Just like you see it in console. I want to mirror whatever comes up on console.

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.

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the reason it is not working the way you are doing it is because everytime you call setText(String) on the JLabel, you are replacing what was there to begin with.

So you would need to build a StringBuffer with all the lines from the input and then do something like label.setText(buffer.toString());

Personally, I would use a JTextArea with a JScrollPane and use the method textArea.append(String).
 
Benjamin Mulder
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

build a StringBuffer with all the lines from the input


Can you please tweak my code above to see what you mean?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Someething like that.
 
Benjamin Mulder
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your inputs man.

Here's the finished and working version....it might help somebody else.


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!