感觉应该可以的。但找不到方法,谢谢各位指教。

解决方案 »

  1.   

    背景图片倒是可以改变 但是我发现改变背景颜色后 JTextArea里的文本显示不了了
      

  2.   

    我在Blog里写了个小例子,你参考下:
    http://blog.csdn.net/mq612/archive/2006/11/10/1377948.aspx
      

  3.   

    mq612(五斗米)的文章写得不错,我稍微改进了一下,实现了背景效果,写了一个类,如下:class ImageTextArea extends JTextArea {
        //
        private ImageIcon image = null;
        //
        public ImageTextArea(ImageIcon image) {
            this.image = image;
        }
        //
        protected void paintComponent(Graphics g) {
            setOpaque(false);
            Dimension d = getSize();
            for (int x = 0; x < d.width; x += image.getIconWidth()) {
                for (int y = 0; y < d.height; y += image.getIconHeight()) {
                    g.drawImage(image.getImage(), x, y, this);
                }
            }
            super.paintComponent(g);
        }}
      

  4.   

    顶,想想也是JTextArea也是继承JPanel的.也有paintComponent的是吧.呵呵
      

  5.   

    如果你只要横线的话...import java.awt.*;import javax.swing.BorderFactory;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.text.BadLocationException;public class T
    {
    public static void main(String[] args) {
    JTextArea ta = new JTextArea(20, 20) {
    @Override
    protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    Insets insets = getInsets();
    Rectangle clip = getVisibleRect();
    int startPos = viewToModel(new Point(clip.x, clip.y));
    Rectangle startRect = null;
    try {
    startRect = modelToView(startPos);
    } catch (BadLocationException e) {
    e.printStackTrace();
    }

    FontMetrics fm = g.getFontMetrics();
    int fontHeight = fm.getHeight();

    int x1 = Math.max(insets.left, clip.x);
    int x2 = Math.min(getWidth()-insets.right, clip.x + clip.width);
    int y = startRect.y + startRect.height - fm.getDescent();

    g.setColor(Color.LIGHT_GRAY);
    while (y <= clip.y + clip.height) {
    g.drawLine(x1, y, x2, y);
    y += fontHeight;
    }
    }
    };
    ta.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    //ta.setLineWrap(true);

    JFrame f = new JFrame();
    f.getContentPane().add(new JScrollPane(ta), BorderLayout.CENTER);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
    }
    }