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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

JTree custom renderer setting selection background color problem

843805Jul 3 2006 — edited May 17 2010
Hi,
I have a JTree with a custom icon renderer that displays an icon. The JTree is part of a TreeTable component. Iam having a problem setting the selection background uniformly for the entire row. There is no problem when there is no row selected in the JTable.

My present code looks like this:

Iam overriding paint in my renderer which extends DefaultCellRenderer.

  	super.paint(g);
   	
   	Color bColor = null; 
   	
   	if(!m_selected) {
   	   	
	   	if(currRow % 2 == 0) {
	   		bColor = Color.WHITE;
	   	} else {
	                                           bColor = backColor;
	   	}
	   	
   	} else {
   		
   		bColor = table.getSelectionBackground();   			bColor = getRowSelectionColor();
   		
   	}
	   	
	   	
	if(bColor != null) {
	
                       g.setColor(bColor);
		    
	    if(!m_selected) {
	     	g.setXORMode(new Color(0xFF, 0xFF, 0xFF));
	    } else {
	   	g.setXORMode(new Color(0x00, 0x00, 0x00));
	}
	    	
I have a color I arrive at using some algorithm that I want using method getRowSelectionColor(). The other cells in the row have this color. But the cell containing the tree node shows different color. Iam not able to arrive at the right combination of the color to set and the xor color so my tree node also looks like the other cells in the row.


It is not a problem really as the table still looks good. Its just that the tree node looks like it has been highlighted and this might cause a problem when a table cell is highlighed later on in the application ( two cells in the row would be highlighted causing confusion).


Any help would be appreciated.

Regards,
vidyut
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 14 2010
Added on Jul 3 2006
7 comments
967 views