我知道的一种比较麻烦:String str = "ajhfa jsfasfjsa 你号!";
AttributedString attribString = new AttributedString(str);
//int index = str.indexOf(3);
attribString.addAttribute(TextAttribute.UNDERLINE,TextAttribute.UNDERLINE_ON,2,4);然后重写JTextPane的public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
AttributedCharacterIterator attIter = attribString.getIterator();
FontRenderContext frc = new FontRenderContext (null,false,false);
TextLayout layout = new TextLayout(attIter,frc);
layout.draw(g2,x,y);
//x,y为你要下划线的地方的坐标。
}
AttributedString attribString = new AttributedString(str);
//int index = str.indexOf(3);
attribString.addAttribute(TextAttribute.UNDERLINE,TextAttribute.UNDERLINE_ON,2,4);然后重写JTextPane的public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
AttributedCharacterIterator attIter = attribString.getIterator();
FontRenderContext frc = new FontRenderContext (null,false,false);
TextLayout layout = new TextLayout(attIter,frc);
layout.draw(g2,x,y);
//x,y为你要下划线的地方的坐标。
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货