Centering text on a Jtextarea or Jtextpane

Asked

Viewed 1,026 times

2

In this image the text is not centered, it is far above the JTextArea: inserir a descrição da imagem aqui

And I would also like the text to begin in the middle of JTextArea and was adjusting as I was writing.

What method can I use to fix this ??

1 answer

2

Using Jpanel you could do so:

StyledDocument doc = textPane.getStyledDocument();
SimpleAttributeSet center = new SimpleAttributeSet();
StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
doc.setParagraphAttributes(0, doc.getLength(), center, false);
  • Hello, he went in the middle, but you know some way to get him aligned according to size width of JTextPane ??

Browser other questions tagged

You are not signed in. Login or sign up in order to post.