You have to use JTextPane, It's better than JTextArea on this case:
try this code:
JTextPane textPane=new JTextPane();
StyledDocument style = textPane.getStyledDocument();
SimpleAttributeSet align= new SimpleAttributeSet();
StyleConstants.setAlignment(align, StyleConstants.ALIGN_RIGHT);
style.setParagraphAttributes(0, style.getLength(), align, false);
modify this code If You want to make the text:
+in the Right :
StyleConstants.setAlignment(align, StyleConstants.ALIGN_RIGHT);
+in the Center :
StyleConstants.setAlignment(align, StyleConstants.ALIGN_CENTER);
+in the Left :
StyleConstants.setAlignment(align, StyleConstants.ALIGN_LEFT);
Take a look at this Centering Text in a JTextArea or JTextPane - Horizontal Text Alignment