It appears JavaFX is stripping control characters before inserting text.
You can’t show the characters directly, but Unicode has a block of characters specifically for showing control characters: Control Pictures.
So, showing a visual representation of a character is as easy as:
char charToDisplay = (c >= 32 || c == '\n' ? c : (char) (c + 0x2400));
You can transform any String fairly easily:
static String makeControlCharactersVisible(String s) {
if (s == null) {
return s;
}
int len = s.length();
StringBuilder visible = new StringBuilder(len);
for (int i = 0; i < len; i++) {
char c = s.charAt(i);
visible.append(c >= 32 || c == '\n' ? c : (char) (c + 0x2400));
}
return visible.toString();
}
In a JavaFX text component, you can intercept the paste:
TextArea textArea = new TextArea() {
@Override
public void paste() {
String text = Clipboard.getSystemClipboard().getString();
replaceSelection(makeControlCharactersVisible(text));
}
};
There are two disadvantages to this:
'\u0011'
or '\u2411'
.