I want to use JTextArea not JTable (since I'm not familiar with it yet)
Well, now is the time to become familiar with a JTable. Use the proper component for the job, that is why multiple components exist. Don't try to fit a square peg in a round hole.
A JTextArea is not the appropriate component for that kind of formatting.
Instead you should be using a JTable
. A JTable
is designed to display data in a row/column format. Check out the section from the Swing tutorial on How to Use Tables for more information and working examples.
If you must use a text component then use a JTextPane. You can manually set the value of a tab so all the text is aligned. The problem with this approach is again you need to determine what the size of each tab should be. So this means either you make a random guess at the size of each column or you iterate through all the data to determine the size. Of course this complicates the code. See: Java Setting Indent Size on JTextPane for an example.
Again, the better solution is to learn to use Swing how it was designed to be used.
String.format("%20s %10s%n", value1, value2)
to print values with a given column width.