1

I want to set bold the charecters within specific range as Bold. How could I do that?

System.out.println("Painting keywords:.......");
    for(int index =0;index<keywordTracer.keywords.size();index++ )
        {
            StyleConstants.setBold(getMainStyle(), true);
            System.out.printf("\nkeywords found at line :%d %d", (int) keywordTracer.keywords.get(index).getFirst(),(int) keywordTracer.keywords.get(index).getSecond());
            docs.setCharacterAttributes( (int) keywordTracer.keywords.get(index).getFirst(),(int) keywordTracer.keywords.get(index).getSecond(),getMainStyle(),true); 
            StyleConstants.setBold(getMainStyle(), false);
        }

The above code doesnt works properly. But,

//System.out.println("Painting Invalid Syntaxes:.......");
    for(int index =0;index<ColorTracer.invalidSyntax.size();index++ )
    {
        StyleConstants.setStrikeThrough(getMainStyle(), true);
        StyleConstants.setForeground(getMainStyle(), Color.orange);
        System.out.printf("\nInvalid syntax at line :%d %d", (int) ColorTracer.invalidSyntax.get(index),(int) ColorTracer.invalidSyntax.get(index)+1 );
        docs.setCharacterAttributes( (int) ColorTracer.invalidSyntax.get(index),1,getMainStyle(),true); //Till only one charecter
        StyleConstants.setStrikeThrough(getMainStyle(), false);

    }

this code works fine.

StyleConstants.setStrikeThrough(getMainStyle(), {SET/RESET}); Is my assumption true about SET/RESET or why boolean is used?

Muthu Ganapathy Nathan
  • 3,199
  • 16
  • 47
  • 77

2 Answers2

1

The boolean is to set it to bold or not.

StyleConstants: setBold(MutableAttributeSet a, boolean b)

Tobias
  • 9,170
  • 3
  • 24
  • 30
1

SOLVED: //MUST SPECIFY A LENGTH IN SECOND ARGUMENT.

docs.setCharacterAttributes( (int) keywordTracer.keywords.get(index).getFirst(),
     (int) keywordTracer.keywords.get(index).getSecond()-(int)
     keywordTracer.keywords.get(index).getFirst(),getMainStyle(), 
     false); //MUST SPECIFY A LENGTH IN SECOND ARGUMENT.

instead of

 docs.setCharacterAttributes( (int) keywordTracer.keywords.get(index).getFirst(),
      (int) keywordTracer.keywords.get(index).getSecond(),getMainStyle(),true); 
mKorbel
  • 109,525
  • 20
  • 134
  • 319
Muthu Ganapathy Nathan
  • 3,199
  • 16
  • 47
  • 77