Ability to smarter text wrapping in JTextArea

Context

At the moment, I have a JTextArea that was created like this:

JTextArea descArea = new JTextArea(); descArea.setFont(style.getFont()); descArea.setLineWrap(true); descArea.setName("descArea"); descArea.setToolTipText(resourceMap.getString("descArea.toolTipText")); descArea.setText(model.getName()); JScrollPane descPane = new JScrollPane(descArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 

When the user enters something into the field, he really wraps up (according to descArea.setLineWrap(true) ), but does it a little awkwardly, breaking words, as in the following example:

alt text

Our software users expect the packaging to become a little smarter and automatically generate something more:

alt text

With the general idea that when they print the last "th", it all moves to the second line along with the insertion point as they are entered (similar to almost any other text editor).


Question

My initial thought was to manually implement this sorting manually using a Key Listener, but I was wondering if there is a better approach / other component that could easily achieve this function?

+4
source share
1 answer

It is already implemented.

  textArea.setWrapStyleWord(true); 
+7
source

All Articles