Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Jul 2010
    Location
    Canada
    Posts
    26
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Syntax Highlighting Problem

    Hi,

    I cannot find my error in my find & replace feature and was wondering if someone could help me find my error. I'm trying to compare a TextPane's (Named:textArea) text against an array.

    Code:
    		//Syntax Colouring Begins Here
    		static String[] javaReserved = {"abstract", "assert", "class", "const", "continue", "default", "enum", "extends", "final", "finally", "goto", "implements", "import", "instanceof", "interface", "native", "new", "package", "private", "protected",
    			"public", "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "try", "void", "volatile"};
    
    		 void colourJavaReservedWords(){
    			if (syntaxColouringEnabled==true) {		
    				StyleConstants.setForeground(style,Color.orange);
    				for(int i=0; i<javaReserved.length; i++){
    					//if (javaReserved[i].indexOf(i).equals(textArea.getText().indexOf(i))) {
    						if (javaReserved[i].equals(textArea.getText().indexOf(i))) {
    							doc.setCharacterAttributes(javaReserved[i],javaReserved.length, textArea.getStyle("orange"),true);
    						}
    					}
    				}
    			}
    Last edited by roher4; 06-01-2011 at 05:28 PM.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •