I've got a JTextArea with setLineWrap(true) and (for now) setWrapStyleWord(true).
The text which is contained in that textArea contains almost no white space, and so the wrapping never occurs. But the text is semi-colon separated. And so I'd like to achieve a wrap style at the ";" instead of at the " ".
With the following text:
hello;world;foo;bar;I am the Wizard;of;Oz
Wrapping like
hello;world;foo;bar;
I am the Wizard;
of;Oz
Instead of (with setWrapStyleWord(true))
hello;world;foo;bar;I
am the Wizard;of;Oz
or
Instead of (with setWrapStyleWord(false))
hello;world;foo;bar;I a
m the Wizard;of;Oz
Any idea on how to realize this ?
The solution is to tweak the ComponentUI used by the JTextArea. See this discussion.
One could create directly a new ComponentUI and assign it to the JTextArea, but I recommend to create a new JTextArea subclass handling all this under the radar.
The Component
The ComponentUI
The View
This one is more tricky. As some information required to do the word wrapping are private in
SeparatedWrappedPlainViewthey have been duplicated (e.g.metrics)