Results 1 to 4 of 4
  1. #1
    prajnajain5 is offline Member
    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Default Checkbox changing row colour

    [QUOTE=facing a problem in rendering.

    i need to change the color of the row to blue when the check box is selected.
    and red when it is deselected.so pl z help me thanking you in advance... here i am posting my code. .[/QUOTE]

    Java Code:
    	public Component getTableCellRendererComponent(JTable table,
    				Object value, boolean isSelected, boolean hasFocus, int row,
    				int column) {
    
    			JLabel parent = (JLabel) super.getTableCellRendererComponent(table,
    					value, isSelected, hasFocus, row, column);
    
    			Object Value = table.getValueAt(row, table.getColumnModel()
    					.getColumnIndex("Stored"));
    			
    
    	
    			try {
    				if (Value.equals("different") ||(Value instanceof JCheckBox)) {
    
    					
    					if(Value instanceof JCheckBox){
    						JCheckBox chk = (JCheckBox)table.getValueAt(row, 3);
    				
    
    				
    
    	
    						
    						if (chk.isSelected()) {
    							if (column == 2) {
    								
    							setForeground(Color.blue);
    
    							btnUpdate.setEnabled(true);
    							}
    						} else {
    							if (column == 2) {
    							setForeground(Color.red);
    							}
    						}
    					}else{
    						if(column == 2)
    							setForeground(Color.red);
    						else
    							setForeground(Color.black);
    					}
    						
    				}
    				
    
    			
    				
    				else {
    					setForeground(Color.black);
    				}
    				return (Component) value;
    			} catch (Exception e) {
    //				e.printStackTrace();
    			}
    Last edited by prajnajain5; 05-18-2013 at 12:05 PM. Reason: not inserted inside code tags

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,937
    Rep Power
    19

    Default Re: Checkbox changing row colour

    Moved to your own thread.
    Please don't hijack someone else's.

    What happens with your code at the moment?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

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

    Default Re: Checkbox changing row colour

    Moved from Advanced Java.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

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

Similar Threads

  1. JTetPane changing text colour help
    By donnierisk in forum AWT / Swing
    Replies: 3
    Last Post: 04-30-2012, 07:16 PM
  2. Replies: 0
    Last Post: 08-14-2010, 10:09 AM
  3. Replies: 3
    Last Post: 07-27-2010, 09:52 AM
  4. changing JFrame colour
    By simo_mon in forum AWT / Swing
    Replies: 0
    Last Post: 08-08-2009, 02:15 AM
  5. Changing text colour in code
    By dbashby in forum New To Java
    Replies: 2
    Last Post: 04-29-2009, 03:32 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
  •