Solved

How to render an icon in a JTable

Posted on 1998-09-06
2
418 Views
Last Modified: 2008-02-01
I need help on how to render an icon in a JTable.
0
Comment
Question by:swilde
2 Comments
 
LVL 3

Accepted Solution

by:
mjenkins earned 50 total points
ID: 1223699
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
 

Author Comment

by:swilde
ID: 1223700
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumDigits  challenge 7 60
allStar challenge 1 41
stringclean challenge 26 55
compre toata in where clue oracle 4 41
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now