好像JTextPane里面就是不能画,我以前也尝试过,也失败了!
最后我只有自己做一个JMyPanel,它继承JPanel,然后实现JTextPane里面需要的功能(如翻页)和画线的功能。你也可以这样做,因为JPanel上也可以写字,也可以画线。

解决方案 »

  1.   

    I think override the paint() method is the proper way.
      

  2.   

    给个小例子:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;public class TextPaneDraw extends JFrame{
    private JTextPane textPane = new JTextPane(){
    public void paintComponent(Graphics g){
    super.paintComponent(g);
    g.drawLine(20, 20, 80, 20);
    }
    };
    public TextPaneDraw(){
    Container c = getContentPane();
    c.setLayout(new BorderLayout());
    c.add(textPane, "Center");
    }
    public static void main(String[] args){
    TextPaneDraw ppd = new TextPaneDraw();
    ppd.setSize(400, 400);
    ppd.setVisible(true);
    }
    }
      

  3.   

    感谢 :juhwali(华仔) ,我的做法是 继承 JTextPane 类,并且过载 JTextPane 的paint()方法,实现在JTextPane 中画出一个距行框,请您看一下能够实现吗? 在下不胜感谢,完成之后另有高分相送
      

  4.   

    感谢 :juhwali(华仔) 以及各位,在juhwali(华仔)的启发下,我已经成功了,再次感谢