2010-10-26 6 views
8

J'ai une jTextArea avec une longue chaîne.
Regardons les choses en usume:ligne de fin automatique dans JTextArea

String str = "this is a toooo long string"; 

Maintenant, je veux montrer cette chaîne dans un JTextArea swing. Mais mon textArea a une taille limitée sur le cadre. Donc, je ne suis pas capable de voir toute la chaîne.
Pour exemple, la zone de texte montre que:
"c'est un t"

Il est possible de textarea éviter des caractères cachés auto introduction '\ n'? Note: Je ne veux pas d'auto scrool.

Merci

Répondre

20
JTextArea textArea = new JTextArea(
    "This is an editable JTextArea. " + 
    "A text area is a \"plain\" text component, " + 
    "which means that although it can display text " + 
    "in any font, all of the text is in the same font." 
); 
textArea.setFont(new Font("Serif", Font.ITALIC, 16)); 
textArea.setLineWrap(true); 
textArea.setWrapStyleWord(true); 

Extrait de: http://download.oracle.com/javase/tutorial/uiswing/components/textarea.html