views:

31

answers:

1

The Context

At the moment, I have a JTextArea that has been created like so:

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 a user types something into the field, it does indeed wrap (as per descArea.setLineWrap(true)), but does it a little clumsily by breaking words like the following example:

alt text

The users of our software are expecting the wrapping to be a little more clever and automatically generate something more like:

alt text

With the general idea being that when they type the last 'th' it all moves down to the second line along with the insertion point as they type (in a way similar to just about every other text editor).


The Question

My initial thought had been to implement this sort of wrapping manually using a Key Listener, but I was wondering if there is a better approach/different component that could achieve this functionality more easily?

+3  A: 

It is already implemented.

  textArea.setWrapStyleWord(true);
Jes