TextArea With Word Wrap

The default behavior for a java.awt.TextArea is to scroll the text you enter to the left once the length of the line of text exceeds the displayable area. When this occurs, a horizontal scroll bar at the bottom of the component allows you to scroll left and right to review the full text. However, in many cases, this may not be the desired behavior. You’ll often want “word wrap” to occur instead, where a word is automatically moved to a new line as the user is typing it if the word is too long to fit on the current line. Even the most simplistic word processors usually support this feature, and its absence can be a great source of frustration for users. Fortunately, there is a simple way to cause TextArea instances to automatically handle word wrap for you. When instantiating the TextArea, specify that there should not be a horizontal scrollbar (using SCROLLBARS_VERTICAL_ONLY), and instead of scrolling text off the visible area of the component, it will use word wrapping to break the text down into separate lines. For example, this code will instantiate a TextArea that displays 4 rows of 30 columns each, with no initial text and provides automatic word wrapping:

 TextArea ta = new TextArea("", 4, 30, TextArea.SCROLLBARS_VERTICAL_ONLY);
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS