如果要自己做,看一下这两个方法能不能满足你的要求 JTextPane jp = new JTextPane();
jp.setSelectedTextColor()
jp.getSelectedText();

解决方案 »

  1.   

    添加相应的监听器:
    jtextpane.addCaretListener( new CaretListener() {
           public void caretUpdate( CaretEvent e ) {
                  int start = e.getDot();//选取的左端位置
                  int end = e.getMark();//选取的右端位置              AttributeSet s = new SimpleAttributeSet();
                  s.setAttribute( "AttributeSet.ColorAttribute",Color.RED );
                  StyleDocument doc = jtextpane.getStyleDocument();
                  doc.setCharacterAttributes( start,dend,s,true );
           }
    } );Just try!!
      

  2.   

    我认为tomcatjava(小鱼儿) 的思路是对的,不过我觉得应该是高亮显示当前行,而不是去设置其显示属性