JTextArea : Java Glossary

JTextArea

a multiline display of text on the screen. Sometimes you permit the user to edit it. You can control where the line breaks are by embedding '\n' characters in your text. The AWT (Advanced Windowing Toolkit) equivalent is called a TextArea. AWT TextArea has an advantage over JTextArea.

Without any coding, with AWT, the user can select, copy and paste, even in an unsigned Applet. However, Applets must be signed for copy/paste to work in Swing. Copy/paste works in Swing without signing for applications.

JTextAreas have use the same font size and colours throughout. If you want to vary them, you will need a JTextPane or a JTextEditorPane.

For a complex display, consider generating a page of HTML (Hypertext Markup Language), XHTML (extensible Hypertext Markup Language) or XML (extensible Markup Language) on the fly, then rendering it, perhaps in an iframe, in a separate browser window, or a separate browser task. Then you can use elaborate CSS (Cascading Style Sheets) style sheets, rowspan and colspan tables. Verifying generated HTML is a snap.

On Mac OS (Operating System) X, I have heard reports you cannot copy/paste from a JTextArea when you do a setEditable( false ).

Wrap

By default JTextArea will not automatically wrap text. You must embed '\n' charactercs in your text where you want the line breaks. To get automatic line wrapping, you need two calls: JTextArea.setLineWrap( true ) and JTextArea.setWrapStyleWord( true ).

Learning More

Oracle’s Javadoc on JTextArea class : available:
Oracle’s Javadoc on Document class : available:

CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/jtextarea.html J:\mindprod\jgloss\jtextarea.html
logo
Please email your , letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email. If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, please quote it and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. Threatening to kill me or spouting obscenities has yet to persuade me to change my mind.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.213]
You are visitor number 28,881.