So I'm writing an application that would output an array of strings, but I would like those strings to be outputted in a very neat columns. The number of those columns depends on the width of the opened Windows console window, as well as the width of the strings themselves, naturally.
An example of what I want would be running dir /w
in the Windows command line:
C:\cygwin64>dir /w
Volume in drive C is
Volume Serial Number is 1337-N00B
Directory of C:\cygwin64
[.] [..] [bin] Cygwin-Terminal.ico Cygwin.bat
Cygwin.ico [dev] [etc] [home] [lib]
[sbin] setup-x86_64.exe [tmp] [usr] [var]
4 File(s) 1 081 410 bytes
11 Dir(s) 311 541 256 192 bytes free
If you go into your console properties and resize the window, you will notice that the dir /w
output will always perfectly fit the width of your window.
QUESTION: Is there a native JDK way to do this "easily"? Alternatively, is there an open source library that can do this? If the answer is "no" to both, would you kindly give some pointers on how you would approach this problem?
Note: I'm only interested in the Windows implementation of this, no need for cross-platform solutions.