Align Strings in columns in JTextArea

后端 未结 4 1218
渐次进展
渐次进展 2020-12-10 06:54

I want to print Strings in JTextArea and align them properly. Its hard to explain so I will upload the screen shot of what I am trying to achieve.

4条回答
  •  旧时难觅i
    2020-12-10 07:04

    Output will be aligned "properly" in your JTextArea only if you use a mono-spaced font. "Andale Mono 14" for example would do the trick.

    Also, in order to make your life easier and avoid the padding hell, use String.format with it's syntax.

    String format = "%1$5s %2$-40s %3$-20s";
    String someLine;
    while (whatEver...) {
       ... 
       someLine = String.format(format, aNum, aName, aDate);
       jTextArea1.append(someLine + "\n");
    }
    

提交回复
热议问题