How to center the text in a JTextArea or JTextPane

2

In this image the text is not centered, it is much higher than JTextArea :

And I would also like the text to start in the middle of JTextArea and adjust as I write.

What method can I use to fix this?

    
asked by anonymous 01.08.2015 / 05:45

1 answer

2

Using Jpanel you could do this:

StyledDocument doc = textPane.getStyledDocument();
SimpleAttributeSet center = new SimpleAttributeSet();
StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
doc.setParagraphAttributes(0, doc.getLength(), center, false);
    
01.08.2015 / 06:37