java - How to Insert Image into JTable Cell -


can point me in right direction on how add image java table cell.

jtable provides default renderer icons. need tell table data stored in given column can choose appropriate renderer. done overriding getcolumnclass(...) method:

import java.awt.*; import javax.swing.*; import javax.swing.table.*;  public class tableicon extends jframe {     public tableicon()     {         imageicon abouticon = new imageicon("about16.gif");         imageicon addicon = new imageicon("add16.gif");         imageicon copyicon = new imageicon("copy16.gif");          string[] columnnames = {"picture", "description"};         object[][] data =         {             {abouticon, "about"},             {addicon, "add"},             {copyicon, "copy"},         };          defaulttablemodel model = new defaulttablemodel(data, columnnames);         jtable table = new jtable( model )         {             //  returning class of each column allow different             //  renderers used based on class             public class getcolumnclass(int column)             {                 return getvalueat(0, column).getclass();             }         };         table.setpreferredscrollableviewportsize(table.getpreferredsize());          jscrollpane scrollpane = new jscrollpane( table );         getcontentpane().add( scrollpane );     }      public static void main(string[] args)     {         tableicon frame = new tableicon();         frame.setdefaultcloseoperation( exit_on_close );         frame.pack();         frame.setvisible(true);     }  } 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -