I am trying to create a xml editor which must have a content assistant. I am new in java so my code isn't working properly.
I am trying to change a text color while typing (words between '<' and '>' including '<' and '>' must be blue), my non working code:
textPane.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent arg0) {
char key = arg0.getKeyChar();
switch(key){
case '<': textPane.setForeground(Color.blue); break;
case '>': textPane.setForeground(Color.black); break;
}
}
Thanks
Your approach is not going to work. You need to work with the
Document
,AttributeSet
andDocumentListener
classes.DocumentListener
tutorial: http://docs.oracle.com/javase/tutorial/uiswing/events/documentlistener.htmlTry doing some reading, and come back with questions about that approach. All you're going to accomplish with your current tack is changing the text color of the entire component, not just the bits between angle brackets.
Is this part of the assignment? It seems a little involved for somebody new to programming.