KidsLovePC Contact Us
  Home   PHP  Graphics ASP  JavaScript   J2EE  HTML  JAVA   Swing   Webtip  Forums  Lyric  Free sheet music  Ringtones
java,jtable,jtree,swing Return to JAVA table list

Best books about JAVA programming:

Icon on JTable column header

The following code will add icon to column row header to JTable. It used TableCellRenderer to change the header's look and feel. Or maybe you want to download the 2 images used by the following program.

//All copyright reserved by
//No redistribution is allowed without author persion and a back link to
// Example from
// is not responsible for your data loss or any damage.

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.AbstractListModel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListCellRenderer;
import javax.swing.ListModel;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.*;
import javax.swing.*;

class myTableHeader implements TableCellRenderer
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
JLabel label=null;

case 0:
label=new JLabel(value.toString (),new ImageIcon("dragonfly.gif"),JLabel.CENTER); //set your image here
case 3:
label=new JLabel(value.toString (),new ImageIcon("dot.gif"),JLabel.CENTER); //set your image here
label=new JLabel(value.toString (),JLabel.CENTER);

return label;

public class IconHeader
//icon column header example
public static void main(String[] args) {
JFrame frame=new JFrame("Row Header Example");
frame.setSize(300, 150);

frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {

//create a table
String headers[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
DefaultTableModel dm = new DefaultTableModel(headers.length , 6);
JTable table = new JTable(dm);
JTableHeader header=table.getTableHeader();
header.setDefaultRenderer(new myTableHeader());

JScrollPane scroll=new JScrollPane(table);
//table header


Sponsored link
Java JTabbedPane
JTabbedPane Preview List
Java JComboBox
JComboBox Preview List
Java JTooltip
JTooltip Preview List
Java JList
JList Preview List
Java JTree
JTree Preview List 1
JTree Preview List 2
JTable Preview List 1
JTable Preview List 2
JTable Preview List 3
JTable Preview List 4
JTable Preview List 5
JTable Preview List 6
JTable Preview List 7
JAVA Jslide
JSlide Preview List



Best books about JAVA programming from Amazon
Professional Java, JDK 5 Edition (Paperback Simply Java Programming: An Application-Driven Tutorial Approach (Paperback) Effective Java Programming Language Guide (Paperback) Head First Java, 2nd Edition (Paperback) Java : An Introduction to Problem Solving and Programming (4th Edition)


Printer Inkjet A Z lyricsLearn ChineseHome|PHP|Swing|HTML|JavaScript|ASP|JAVA|Forum|WebTip|Contact Us
Copyright © All rights reserved(new). Privacy|Copyright
designed by

Please help us cover the web site maintenance fee.
barcode scanner Thermal Printer credit card machine bar code printer