Question

I've been messing around with various text components and I now come here for answers.

What I need is a area in which user can enter text using keyboard and/or copy/paste. These are the requirements of the component:

Word wrap, ability to limit number of rows (word wraped ones), ability to prevent user from entering certain characters (or hitting enter for a newline), ability to expand and reduce height according to its content (to make content fit into the component and to have no (couple of pixels are fine) exces height left, ability to detect change of its height, either directly or by tracking the line number.

Was it helpful?

Solution

Have a look at the different Text Components provided by the Java API here: Using Text Components

in the above it has 3 different types of text components:

  • Text Controls
  • Plain Text Areas
  • Styled Text Areas

And it looks like the definition of the last Styled Text Areas fits your needs:

A styled text component can display editable text using more than one font. Some styled text components allow embedded images and even embedded components. Styled text components are powerful and multi-faceted components suitable for high-end needs, and offer more avenues for customization than the other text components. Because they are so powerful and flexible, styled text components typically require more initial programming to set up and use. One exception is that editor panes can be easily loaded with formatted text from a URL, which makes them useful for displaying uneditable help information.

These would include the likes of:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top