开发者

what is the meaning of boolean argument in StyleConstants.setBold?

开发者 https://www.devze.com 2023-04-10 21:18 出处:网络
I want to set bold the charecters within specific range as Bold. How could I do that? System.out.println(\"Painting keywords:.......\");

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.keyword开发者_如何学运维s.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?


The boolean is to set it to bold or not.

StyleConstants: setBold(MutableAttributeSet a, boolean b)


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); 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号