拜托...各位哥哥姐姐...告诉我在在TextArea里面显示图片咯...
谢谢....谢谢.....

解决方案 »

  1.   

    拜托....
    告诉我在在TextArea里面怎么显示图片咯...
      

  2.   

    ImageIcon icon = new ImageIcon("Calv.gif");
    JLabel calv_label = new JLabel("这是 Calvin", icon,                               SwingConstants.LEFT);
      

  3.   

    在JLable里面我知道如何添加ICON,我要在Jtextarea里面添加图片哦 。
      

  4.   

    JTextArea使用的Document只支持纯文本类型,建议使用JTextPane,除了添加图片外,还能给文字设置颜色、字体效果等。
      

  5.   

    给你个例子:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.text.*;
    import java.io.*;public class Test {
      JFrame frame;
      JTextPane textPane;
      File file;
      Icon image;  public Test(){
        frame = new JFrame("JTextPane");
        textPane = new JTextPane();
        file = new File("icon.gif");
        image = new ImageIcon(file.getAbsoluteFile().toString());
      }  public void insert(String str, AttributeSet attrSet) {
        Document doc = textPane.getDocument();
        str ="\n" + str ;
        try {
          doc.insertString(doc.getLength(), str, attrSet);
        }
        catch (BadLocationException e) {
          System.out.println("BadLocationException: " + e);
        }
      }  public void setDocs(String str,Color col,boolean bold,int fontSize) {
        SimpleAttributeSet attrSet = new SimpleAttributeSet();
        StyleConstants.setForeground(attrSet, col);
        //颜色
        if(bold==true){
          StyleConstants.setBold(attrSet, true);
        }//字体类型
        StyleConstants.setFontSize(attrSet, fontSize);
        //字体大小
        //StyleConstants.setFontFamily(attrSet, "黑体");
        //设置字体
        insert(str, attrSet);
      }  public void gui() {
        textPane.insertIcon(image);
        setDocs("第一行的文字",Color.red,false,20);
        setDocs("第二行的文字",Color.BLACK,true,25);
        setDocs("第三行的文字",Color.BLUE,false,20);
        frame.getContentPane().add(textPane, BorderLayout.CENTER);
        frame.addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }});
        frame.setSize(200,300);
        frame.setVisible(true);
      }
      public static void main(String[] args) {
        Test test = new Test();
        test.gui();
      }
    }
      

  6.   

    JTextArea jPanel4 = new JTextArea (){
        public void paintChildren(Graphics g) {
          if (backgroundImg != null) {
            g.drawImage(backgroundImg.getImage(), 0, 0,
                        backgroundImg.getImage().getWidth(null),
                        backgroundImg.getImage().getHeight(null), null);
          }
          super.paintChildren(g);
        }  };