CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 1999
    Posts
    2

    How to show ImageIcon inside cell of JTable



    I'am trying to display an ImageIcon in a JTable column. The only problem
    is that I'am not seeing the ImageIcon but a String value "com.sun.java.swing.ImageIcon@266b10".
    I think this is the memory address of the Icon. I thought Boolean, Number, ImageIcon and Object
    are four types of data supported by JTable. Isn't it?

    Does anyone has same experience and can share solution with me?

    Thanks,
    Hong Hsu [email protected]




  2. #2
    Join Date
    Apr 1999
    Location
    Bangalore,India
    Posts
    43

    Re: How to show ImageIcon inside cell of JTable

    It might be a problem with your CellRenderer. Because this value is nothing but the ImageIcon.toString() value. That means the CellRenderer has converted your ImageIcon object to a string and displaying it rather than displaying as a component. So check your CellRenderer.

    regards,
    arun...


  3. #3
    Join Date
    Jun 1999
    Posts
    9

    Re: How to show ImageIcon inside cell of JTable

    Just set the icon of your cell renderer (if you are using or extending from DefaultTableCellRenderer, then it is just a JLabel and you can set an icon in JLabel:

    class ErrorMessageCellRenderer extends DefaultTableCellRenderer
    {
    public void setValue(Object value)
    {
    if (value != null)
    {
    if (value instanceof ErrorMessage)
    {
    ErrorMessage em = (ErrorMessage)value;
    setText(em.message);
    setIcon(em.icon);
    }
    else
    {
    setText(value.toString());
    }
    }
    else
    {
    setText(" ");
    }
    }
    }


  4. #4
    Join Date
    Jul 1999
    Posts
    2

    Re: How to show ImageIcon inside cell of JTable

    Just modifying three line code of getColumnClass() method solves the problem. Following code say all:

    public Class getColumnClass(int c) {
    if(c == 0)
    return ImageIcon.class;

    return Object.class;
    }




    Thanks for your response.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured