Solved

How to render an icon in a JTable

Posted on 1998-09-06
2
424 Views
Last Modified: 2008-02-01
I need help on how to render an icon in a JTable.
0
Comment
Question by:swilde
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jdbc error in jsp application 20 86
Is Applet the way to go for my drag and drop system? 8 48
Java Eclipse Loop 3 44
netbeans can not run self signed app 8 35
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

738 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