JTextPane syntax syntax - limitation of my formatting?
I am currently programming an IDE and I am using JTextPane as a "code editor".
Now I am trying to add syntax highlighting to the JTextPane, but I have some problems ...
I am using HTML to replace http://img21.imageshack.us/img21/6185/910b3b10cad4487f9c96d43.png with :
private void jTextPane1KeyTyped(java.awt.event.KeyEvent evt) {
String SyntaxedCode = jTextPane1.getText();
jTextPane1.setText(SyntaxedCode.replaceAll("//", "<span style='color: green'>//</span>"));
}
Getting the result:
Now the part I'm struggling with is that the JTextPane limits my spacing ... I can only add one or two spaces in a row and then the JTextPane just stops accepting spaces. Also, I cannot use the enter key to go to a new line.
Why does it restrict me in this way and how can I avoid it?
Thanks in advance;
source to share
1) to listen for keyboard events on JTextComponents then you have DocumentListener tools
2) in case you want to filter, block or modify keyboard input, and before that content is posted in the GUI, then you are looking for DocumentFilter
3) I would suggest to implement Highlighter , of course you can use HTML-text, but it's better to create your own HtlmEditorKit
4) forgot to listeng in Swing JComponents with KeyListener , use KeyBindings
source to share