2010-07-09 8 views

risposta

55

È necessario utilizzare un JTextPane e utilizzare gli attributi. Il seguente dovrebbe centrare tutto il testo:

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

Edit:

centratura verticale non è supportato per quanto ne so. Ecco un codice che potresti trovare utile: Vertical Alignment of JTextPane

+1

Che dire se volessi anche che fosse centrato verticalmente? – Awaken

+0

@Awaken, Vedi modifica sopra: – camickr

+0

sì ... funziona! : D – gumuruh

Problemi correlati