Results 1 to 3 of 3
  1. #1
    nsyncpilu is offline Member
    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Default model.addrow with background color

    Hy ,

    I have a table , in which i am adding new rows , after 6 rows with data I want to add a empty row with the background color red then another 6 rows with white background and so on

    Java Code:
    private void populate(){
    
            DefaultTableModel model = (DefaultTableModel) table.getModel();
            int i,j;
            for(j=0;j<6;j++){
    
                       for(i=0;i<6;i++){
                                model.addRow(new Object[]{"dada","dadaddd"});
                       }
    
                       model.addRow(new Object[]{"",""}); //<-this is the red row i want to add 
           }
    
    
    
    }



    How can i change the color of the empty row?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: model.addrow with background color

    Check out How to use Tables in Oracle's Tutorial. Especially the "Concepts: Editors and Renderers" section that explains how the cells aren't really components (with background colour etc).

    It sounds like you could use a custom renderer which sets the background colour based on the row index.
    Last edited by pbrockway2; 12-15-2011 at 01:47 AM.

  3. #3
    nsyncpilu is offline Member
    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Default Re: model.addrow with background color

    I read the article before but i got no results ... that why i asked on a forum..
    Thanks

Similar Threads

  1. How to change background color
    By Jeffrey4u in forum Sun Java Wireless Toolkit
    Replies: 0
    Last Post: 10-22-2011, 08:32 AM
  2. Background color of window
    By Annie George in forum NetBeans
    Replies: 1
    Last Post: 09-18-2010, 09:52 AM
  3. background color with jpanel
    By hannerz06 in forum New To Java
    Replies: 6
    Last Post: 03-31-2010, 03:25 AM
  4. Color-changing model
    By higuchi in forum New To Java
    Replies: 1
    Last Post: 03-19-2009, 07:29 AM
  5. window background color?
    By javan00b in forum New To Java
    Replies: 3
    Last Post: 01-29-2008, 10:43 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
  •