Does anyone knows how to detect printable characters in java?
After a while ( trial/error ) I get to this method:
public boolean isPrintableChar( char c ) {
Character.UnicodeBlock block = Character.UnicodeBlock.of( c );
return (!Character.isISOControl(c)) &&
c != KeyEvent.CHAR_UNDEFINED &&
block != null &&
block != Character.UnicodeBlock.SPECIALS;
}
I'm getting the input via KeyListener and come Ctr-'key' printed an square. With this function seems fairly enough.
Am I missing some char here?
Character.isPrintable()
method. Another technique is to compareCharacter.getType(ch)
with all of the printable Unicode character classes, which still seems like a lot of effort to go to. – Megaspore