Delayed text color change in Swing text field

前端 未结 3 1577
花落未央
花落未央 2020-12-21 13:24

Is it possible to change the color of a text in a text field?I am trying to build an interpreter, so I was wondering on how would you change the color of the text in real ti

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-21 13:56

    Try this:

    HighlightPainter greenPainter = new DefaultHighlighter.DefaultHighlightPainter(Color.GREEN);
    
    //in a thread...    
    Highlighter h = tf.getHighlighter();
    h.addHighlight(offset, offset+length, greenPainter); 
    

提交回复
热议问题