How to get Icon from JTable

后端 未结 4 1991
既然无缘
既然无缘 2020-11-30 15:38

I have changed the cell render in JTable to show image instead of text using the following code:

base_table.getColumnModel().getColumn(3).setCel         


        
4条回答
  •  死守一世寂寞
    2020-11-30 16:10

    You should already have all the images in your table model. So you just have to get the images from the model, and then save them in your database.

    In your cell renderer you have the type Object value, then you use (ImageIcon) value to cast it to an ImageIcon in lbl.setIcon((ImageIcon) value);

    You can do the exaclty the same when you get the data from your model:

    ImageIcon myIcon = 
             (ImageIcon) base_table.getModel().getValueAt(rowIndex, 3);
    

    where 3 is your columnIndex for the column with images, and rowIndex is the row you want.

提交回复
热议问题