Centralização de texto

Oi gente, procurei por algum topico que tenha falando sobre centralizar texto no JTextArea, mas so encontrei 1 com 2 resposta dizendo pra não duplicar post. mas n vi nenhum post duplicado da passoa. :roll:

então venho a perguntar.
como fazer um alinhamento no JTextArea.
no meu caso o Central…

Fonte: http://forum.java.sun.com/thread.jspa?threadID=342068&forumID=57

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
 
public class TextPaneAttributes extends JFrame
{
	public TextPaneAttributes()
	{
		JTextPane textPane = new JTextPane();
		StyledDocument doc = textPane.getStyledDocument();
 
		//  Set alignment to be centered for all paragraphs
 
		MutableAttributeSet standard = new SimpleAttributeSet();
		StyleConstants.setAlignment(standard, StyleConstants.ALIGN_CENTER);
		doc.setParagraphAttributes(0, 0, standard, true);
 
		//  Define a keyword attribute
 
		MutableAttributeSet keyWord = new SimpleAttributeSet();
		StyleConstants.setForeground(keyWord, Color.red);
		StyleConstants.setItalic(keyWord, true);
 
		//  Add initial text
 
		textPane.setText( "one\ntwo\nthree\nfour\nfive\nsix\nseven\neight\n" );
 
		//  Highlight some keywords
 
		doc.setCharacterAttributes(0, 3, keyWord, false);
		doc.setCharacterAttributes(19, 4, keyWord, false);
 
		//  Add some text
 
		try
		{
			doc.insertString(0, "Start of text\n", null );
			doc.insertString(doc.getLength(), "End of text\n", keyWord );
		}
		catch(Exception e) {}
 
		//  Add text pane to frame
 
		JScrollPane scrollPane = new JScrollPane( textPane );
		scrollPane.setPreferredSize( new Dimension( 200, 200 ) );
		getContentPane().add( scrollPane );
 
		//  Add a bold button
		JButton button = new JButton("bold");
		getContentPane().add(button, BorderLayout.SOUTH);
		button.addActionListener( new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				new StyledEditorKit.BoldAction().actionPerformed(null);
			}
		});
 
	}
 
	public static void main(String[] args)
	{
		TextPaneAttributes frame = new TextPaneAttributes();
		frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
		frame.pack();
		frame.setVisible(true);
	}
}

incrivel…
nomalmente os topicos que passam pra segunda pagina em diante quase nem são vistos, so por ocasião alguem responde por necessidade em relação ao topico, mas fora isso as pessoas (a maioria) tendem a visualizar apenas a primeira pagina tendo visto que as demais antigas já foram respondidas.

Irá ser muito útil “t_java”.
Agradeço mto ter respondido a duvida.
vlw. :stuck_out_tongue: