java - how to set an image for jtable fixed column, when i am running, it's getting an image path only -



java - how to set an image for jtable fixed column, when i am running, it's getting an image path only -

i created programme set imageicon in jtable fixed column, created jtable , getting database records, set first column fixed column. set image icon in fixed column. when compiling program, getting path of imageicon not getting image. fixed imageicon in project bundle folder.

code used public void frm_flxd_database() { try{ tmprow=0; tmpmainprj.prj_db_connection_assgn(); tmpflxmdl =(defaulttablemodel)flxd.getmodel(); tmpflxdrow = 0; tmpflxst=tmpgprjvardec.gcontn.createstatement(); tmpflxdrs=tmpflxst.executequery("select * activitymaster"); prj_flx_deftl_assgn(flxd, "begin"); tmpflxdrs.first(); { flxd.setvalueat(tmpflxdrs.getstring("actvtydesc"), tmprow,1); flxd.setvalueat(tmpflxdrs.getstring("actvtycode"), tmprow,2); flxd.setvalueat(tmpflxdrs.getstring("dispstatus"), tmprow,3); flxd.setvalueat(tmpflxdrs.getstring("actvtyid"), tmprow,4); tmpflxmdl.addrow(new object[]{""}); tmprow = tmprow + 1; }while(tmpflxdrs.next()); frm_flxd_ptr_data_assgn(tmpflxdrow); } catch(exception e){ system.out.println(e); } } private void frm_flxd_ptr_data_assgn(int pflxrow) { tmpflxdrow = prj_flx_ptr_assgn(flxd, pflxrow, tmpflxdrow); } private int prj_flx_ptr_assgn(jtable pflx, int pcurrow, int pprvrow) { imageicon tmpicon; system.out.println(pcurrow); system.out.println(pprvrow); if (pcurrow != pprvrow){ tmpicon = new imageicon(getclass().getresource("blank.gif")); pflx.setvalueat(tmpicon,pprvrow,0); system.out.println(tmpicon); } tmpicon = new imageicon(getclass().getresource("pointer.gif")); pflx.setvalueat(tmpicon,pcurrow,0); system.out.println(tmpicon); return(pcurrow); }

jtable knows icon/imageicon, simple illustration

import java.awt.borderlayout; import java.awt.dimension; import java.awt.eventqueue; import javax.swing.*; import javax.swing.table.*; public class tableicon extends jframe implements runnable { private static final long serialversionuid = 1l; private jtable table; private jlabel mylabel = new jlabel("waiting"); private int pheight = 40; private boolean runprocess = true; private int count = 0; public tableicon() { imageicon erroricon = (imageicon) uimanager.geticon("optionpane.erroricon"); imageicon infoicon = (imageicon) uimanager.geticon("optionpane.informationicon"); imageicon warnicon = (imageicon) uimanager.geticon("optionpane.warningicon"); string[] columnnames = {"picture", "description"}; object[][] info = {{erroricon, "about"}, {infoicon, "add"}, {warnicon, "copy"},}; defaulttablemodel model = new defaulttablemodel(data, columnnames); table = new jtable(model) { private static final long serialversionuid = 1l; // returning class of each column allow different // renderers used based on class @override public class getcolumnclass(int column) { homecoming getvalueat(0, column).getclass(); } }; table.setrowheight(pheight); table.setpreferredscrollableviewportsize(table.getpreferredsize()); jscrollpane scrollpane = new jscrollpane(table); add(scrollpane, borderlayout.center); mylabel.setpreferredsize(new dimension(200, pheight)); mylabel.sethorizontalalignment(swingconstants.center); add(mylabel, borderlayout.south); eventqueue.invokelater(new runnable() { public void run() { } }); new thread(this).start(); } public void run() { while (runprocess) { seek { thread.sleep(750); } grab (exception e) { e.printstacktrace(); } swingutilities.invokelater(new runnable() { @override public void run() { imageicon myicon = (imageicon) table.getmodel().getvalueat(count, 0); string lbl = "jtable row @ : " + count; mylabel.seticon(myicon); mylabel.settext(lbl); count++; if (count > 2) { count = 0; } } }); } } public static void main(string[] args) { tableicon frame = new tableicon(); frame.setdefaultcloseoperation(exit_on_close); frame.setlocation(150, 150); frame.pack(); frame.setvisible(true); } }

java swing jtable imageicon

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -