JTextArea : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

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:

This page is posted
on the web at:

http://mindprod.com/jgloss/jtextarea.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\jtextarea.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[3.144.6.144]
You are visitor number