| |
You are here: Experts > Computing/Technology > Focus on Java > Java > JLabel in JTable
Java - JLabel in JTable
Expert: Artemus Harper - 10/30/2009
Question Hi, Harper
I m Nirav Raval Frm India. At now i m develop one Windowbased Application in java with Netbeans IDE 6.0 , in which I have to develop a printable customer bill. In which I m using JTAble to use as a printable bill. Here I have to attch one Image As A logo in the first row of JTable.
So My Question is how can I Attch that logo with help of JLabel in JTable at particular Cell.?
Thanks In Advance
Bi.
Answer Set the default renderer (for the Object class) in your JTable (using setDefaultRenderer) to a subclass of DefaultTableCellRenderer. In this subclass, override the getTableCellRendererComponent method to return your own JLabel that has your icon in it (just check too see if row and column match what you want, if they don't just call the super implementation).
Also note that you can render html in a JLabel, so using table.setValueAt("<html><img src=\""+YourClass.class.getResource("<<your image Path>>")+"\"/></html>", 0, 0);
will load an image from your jar into the cell. However, unless you adjust the cell width your image may be cut off.
Add to this Answer Ask a Question
|
|