Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: mode.addRow with background color

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default mode.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

    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?
    Last edited by nsyncpilu; December 14th, 2011 at 07:37 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: mode.addRow with background color

    Use a custom TableCellRenderer. The tutorial has great examples for how to do this
    How to Use Tables (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: mode.addRow with background color

    I have read the article but i still dont know how to implement it.
    Please help me

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: mode.addRow with background color

    Quote Originally Posted by nsyncpilu View Post
    I have read the article but i still dont know how to implement it.
    Please help me
    What did you try? Did you try to use some of the code examples in the tutorial?

Similar Threads

  1. Replies: 0
    Last Post: November 13th, 2011, 10:27 PM
  2. text color changer based on words/ word classification by color
    By knoxy5467 in forum Java Theory & Questions
    Replies: 25
    Last Post: June 15th, 2011, 07:52 AM
  3. set Background Excel cell color using POI API
    By ngamal in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 26th, 2011, 11:20 AM
  4. [SOLVED] Jython interactive mode
    By helloworld922 in forum Java Theory & Questions
    Replies: 1
    Last Post: July 19th, 2010, 06:39 AM
  5. Works on debug mode but not on run mode
    By alfonsoraul in forum Member Introductions
    Replies: 0
    Last Post: April 14th, 2010, 02:58 PM