colorpanel.java

来自「这是一个汉诺塔程序」· Java 代码 · 共 36 行

JAVA
36
字号
//错误显示部分 特定区域高亮显示 需要读到特定行号!!
import javax.swing.*;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import java.awt.*;

public class ColorPanel{
	//从JTextPane 里直接得到doc
	 JTextPane textPane = new JTextPane();
     StyledDocument doc = textPane.getStyledDocument();
     

	public  void change(String s,int line,Color c){
		//可扩展的属性集合 
		MutableAttributeSet att= new SimpleAttributeSet();
		
		//红色显示
		StyleConstants.setForeground(att, Color.red);
		
		//  !!!将属性集合添加到错误域
		doc.setCharacterAttributes(0, 0, att, true);
		
		
		
	}
	//错误信息 String s
	public  void append(String s){
		//向控制台输入错误信息
		 textPane.setText(s);
		}

	

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?