Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2009
    Rep Power

    Default Coloring JTable cells

    Hi, this is another JTable question. This forum was so helpful with my last problem, I thought I would return!

    I have a table whose cells are filled with strings at the moment. I want to color the cell depending on what string is in the cell, but i want to maintain the ability that columns get highlighted when selected.

    I did this by replacing each cell with a JLabel that contained a .jpg of the particular colored string. but then my columsn would not highlight.

    Just to clarify: I have strings such as: "A" "T" "C" and "G" and a few others and I want the background of the cell to be a particular color....but maybe changing the color of the font will be sufficient.

    Please and Thank you!!

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power


    Start reading the API documentation for the TableCellRenderer interface and its implementation the DefaultTableCellRenderer class. It is a 'rubber stamp' that delivers the component to be shown in the visual representation of a table. The default implementation delivers a JLabel. If you override that class you can give that label an appropriate background colour. Start reading and don't fiddle with those JLabels yourself, it has been done for you.

    kind regards,


  3. #3
    Join Date
    Nov 2009
    Rep Power

Similar Threads

  1. Coloring an image
    By Twitchy5 in forum AWT / Swing
    Replies: 19
    Last Post: 09-12-2009, 04:44 PM
  2. How to merge cells of JTable
    By nehaa in forum AWT / Swing
    Replies: 1
    Last Post: 05-19-2009, 02:07 PM
  3. how to merge cells /colspan in Jtable
    By ravrajesh.ap in forum AWT / Swing
    Replies: 0
    Last Post: 01-03-2009, 05:25 PM
  4. Getting objects from JTable Cells.
    By girigl in forum AWT / Swing
    Replies: 3
    Last Post: 12-24-2008, 11:46 AM
  5. Replies: 0
    Last Post: 07-25-2008, 03:31 PM

Posting Permissions

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