Search code examples
javaswingiconsjtableheader

JTable, how can I put icons in the header?


i'm trying to render some icons in a JTable header without success. I've already tried something like this: http://www.java2s.com/Tutorial/Java/0240__Swing/CustomizingColumnHeaderswithIcons.htm but it doesn't show any icon in the header. How can I reach this goal?


Solution

  • Your link is good code , but in fact when you load a picture using absolute path or relative path , this code is not portable .So it is better to load picture from a class. Levels : 1) Create a empty class with this name : ImageResources 2) Please copy your picture 3) Please find ImageResources class in package explorer (in eclipse) and do right click on it (ImageResources) and press "Paste" menuItem. 4) Finally you need a small change in your code like this

    ImageIcon blueIcon = new ImageIcon(ImageResources.class.getResource(yourPictureName));
    

    It is working :)