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.
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");
}
Use a JTable instead (for what is apparently tabular information). See How To Use Tables for more details & working examples.
You can also change the font of the JTextArea if it is allowed in your problem
textArea.setFont(new Font("monospaced", Font.PLAIN, 12));
You may use HTML with swing component or use JEditorPane.
JLabel jt=new JLabel();
jt.setText("<html>
<table border='1'>
<tr><th>No</th><th>Name</th></tr>
<tr><td>1</td><td>Mr.A</td></tr></table></html>");