当然可以,帮JTable定义一个render类,采用JLabel,
在JLabel设置图片得了

解决方案 »

  1.   

    能具体一点吗?我以前从没用过JLabel
      

  2.   

    啊不用了,jtable默认render是jlabel的,你自己定义一个tablemodel
    扩展AbstractTableModel,使用ImageIcon做字段,那么jtable就自己会显示图片了
      

  3.   

    例子我也没有你自己写吧
    class MyTableModel extends AbstractTableModel {
            final String[] columnNames = {"First Name", 
                                          "Last Name",
                                          "photo",
                                          "# of Years",
                                          "Vegetarian"};
            final Object[][] data = {
                {"Mary", "Campione", 
                 new ImageIcon("filename");new Integer(5), new Boolean(false)},
                {"Alison", "Huml", 
                 new ImageIcon("filename"),new Integer(3), new Boolean(true)};
           //只需要生成ImageIcon对象就可以
            public int getColumnCount() {
                return columnNames.length;
            }
            
            public int getRowCount() {
                return data.length;
            }        public String getColumnName(int col) {
                return columnNames[col];
            }        public Object getValueAt(int row, int col) {
                return data[row][col];
            }
     public Class getColumnClass(int c) {
                return getValueAt(0, c).getClass();
            }
            public boolean isCellEditable(int row, int col) {
              return false;
            }
    public void setValueAt(Object value, int row, int col) {
    ...
    }
      

  4.   

    试试这个,图片名字,自己还!import java.awt.*;
    import java.awt.Graphics;
    import java.awt.Image.*;
    import javax.swing.*;class showImage extends JPanel{ public static void main(String[] args){        int width;
            int height;        ImageIcon icon = new ImageIcon("insect.jpg");        width   = icon.getIconWidth();
            height  = icon.getIconHeight();        JLabel label = new JLabel(icon);
            label.setHorizontalAlignment(SwingConstants.LEFT);
            label.setVerticalAlignment(SwingConstants.TOP);        JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            f.setContentPane(label);
            f.setSize(width,height);
            f.setVisible(true);
    System.out.println("Hello World!");
    }
    }
      

  5.   

    gdsean(摇滚java):我按你说的那样试了一下,可是JTable上没有显示图形呀,
      代码如下,我该怎么改?import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.table.AbstractTableModel;public class Frame1 extends Frame{
      BorderLayout borderLayout1 = new BorderLayout();
      JTable jTable1 = new JTable();
        
      public static void main(String[] args){
         Frame1 myframe=new Frame1();
         myframe.setSize(new Dimension(250,250));
         myframe.setVisible(true);
      }  public Frame1() {
        super();
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }  private void jbInit() throws Exception {    
        System.out.print("Header Length="+header[0]);
        //jTable1=new JTable(data,header);
        MyTableModel myTableModel=new MyTableModel();
        JTable table = new JTable(myTableModel);
        jTable1.setCellSelectionEnabled(true);
        this.setTitle("Excel lent JTable");
        this.addWindowListener(new java.awt.event.WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            this_windowClosing(e);
          }
        });
        jTable1.setBackground(Color.pink);
        this.setLayout(borderLayout1);
        this.setSize(new Dimension(400,300));
        this.setBackground(Color.white);
        this.add(jTable1, BorderLayout.CENTER);
         //------------------------------
         //ExcelAdapter myAd=new ExcelAdapter(jTable1);
      }  void this_windowClosing(WindowEvent e) {
         System.exit(0);
      }
    }
    class MyTableModel extends AbstractTableModel {
            final String[] columnNames = {"photo"};
            final Object[][] data = {
                { new ImageIcon("f:/temp/save/spcinit.gif")}
            };
          //只需要生成ImageIcon对象就可以
            public int getColumnCount() {
                return columnNames.length;
            }        public int getRowCount() {
                return data.length;
            }        public String getColumnName(int col) {
                return columnNames[col];
            }        public Object getValueAt(int row, int col) {
                return data[row][col];
            }
            public Class getColumnClass(int c) {
                return getValueAt(0, c).getClass();
            }        public boolean isCellEditable(int row, int col) {
              return false;
            }}
      

  6.   

    我去sun网站看了,也试了一下,在JTable放了一个Button,那一栏显示为:ava.awt.Button[button0,0,0,0x0,invalid,label=button1]