Results 1 to 3 of 3
  1. #1
    RickAintree is offline Member
    Join Date
    Dec 2010
    Posts
    22
    Rep Power
    0

    Default I Only need the color of a cell to change not the entire row

    Java Code:
    public class MultiTargetColRenderer implements javax.swing.table.TableCellRenderer {
            java.awt.Color foreground;
            java.awt.Color background;
            java.awt.Font font;
    
            private javax.swing.table.DefaultTableCellRenderer MULTI_RENDERER = new javax.swing.table.DefaultTableCellRenderer();
    
            public java.awt.Component getTableCellRendererComponent(javax.swing.JTable tblTable, java.lang.Object objValue, boolean blnIsSelected, boolean blnHasFocus, int intRow, int intColumn) {
    
                java.awt.Component multirenderer = MULTI_RENDERER.getTableCellRendererComponent(tblTable, objValue, blnIsSelected, blnHasFocus, 0, 6);
    
    
               
    
               if (tbeResults.getValueAt(0, 6).toString().equals("Active")) {
                    //Set font colour to blue
                    foreground = java.awt.Color.blue;
    
    
                } else {
                     
                    foreground = java.awt.Color.RED;
                    
                }
               
    
    
                
                //Assign colours
                multirenderer.setForeground(foreground);
                multirenderer.setBackground(background);
                multirenderer.setFont(font);
    
                return (multirenderer);
            }
        }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    You already have a thread running for this topic, so why the double post?
    How to change color of a cell in a Jtable based on a criteria

    db

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Replies: 6
    Last Post: 05-14-2011, 06:48 AM
  2. Replies: 5
    Last Post: 12-20-2010, 08:31 PM
  3. Can I change the border of a JPanel cell?
    By ryuzog in forum New To Java
    Replies: 2
    Last Post: 10-10-2010, 06:05 AM
  4. Replies: 2
    Last Post: 08-27-2010, 05:15 AM
  5. Color cell in JTable
    By ippacciani in forum AWT / Swing
    Replies: 3
    Last Post: 03-25-2009, 11:53 AM

Posting Permissions

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