我知道的一种比较麻烦: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为你要下划线的地方的坐标。
}