• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 430
  • Last Modified:

How to render an icon in a JTable

I need help on how to render an icon in a JTable.
0
swilde
Asked:
swilde
1 Solution
 
mjenkinsCommented:
Use this as your cell renderer for the column in question:

public class MyCellRenderer
{
      public Component getTableCellRendererComponent(
            JTable table, java.lang.Object value, boolean isSelected, boolean hasFocus,int row,int column)
      {      
            if( value instanceof Icon )
                  return new JLabel( (Icon)value );
            else
                  return new JLabel( value.toString() );
      }
}
0
 
swildeAuthor Commented:
Thanks for the response.  The only thing missing was that the class needed to implement TableCellRenderer.  The code worked like a charm.  Now if only I can figure out why it worked!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now