Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem in setting the background color of jtable with Nimbus

853982Aug 23 2011 — edited Aug 23 2011
Hi
I have created a java swing application. In which I am using JTable.
When creating a simple JTable and displaying with Nimbus, the row background color alternates between white and a light blue-grey.
I want the table with single colour. Only the first column should be grey colour and other should be white.
I used this code to set the background and foreground colour.
public Component prepareRenderer
    (TableCellRenderer renderer, int index_row, int index_col){       
            Component objComponent = super.prepareRenderer(renderer, index_row, index_col);          
            Color objGreyColour = new Color(240,240,240);
            Color objWhiteColour = new Color(255,255,255);
            if(index_col == 0){
                objComponent.setBackground(objGreyColour);
                objComponent.setFont(new java.awt.Font(CommonClass.getFontName(),java.awt.Font.BOLD, CommonClass.getFontSize()));
                objComponent.setForeground(Color.BLACK);
            }else{                
                setSelectionBackground(Color.BLUE);
                objComponent.setBackground(objWhiteColour);
                objComponent.setForeground(Color.BLACK);
            }           
            return objComponent;
        }
Look wise it is fine but when i try to select the cell it is not highlighting the cell and also i m not able to select multiple cell with ctrl key.
Any help would be appreciated

Thanks
Sonal
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 20 2011
Added on Aug 23 2011
1 comment
208 views