/** * Converts a string to the hex representations of its chars. */ Selection[] selection = textArea.getSelection(); String s = textArea.getSelectedText(selection[0]); StringBuffer sb = new StringBuffer(); for (int i = 0; i < s.length(); i++) { String b = Integer.toHexString((int) s.charAt(i)); for (int n = b.length(); n < 2; n++) { sb.append("0"); } sb.append(b.toUpperCase()); } textArea.setSelectedText(selection[0],sb.toString());