473,385 Members | 1,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Bug in TreeCellRenderer.setTextNonSelectionColor ?

I think I have found a bug in the behavior of the TreeCellRenderer
setTextNonSelectionColor method. Instead of setting the text color for
the current cell, it sets the color of the following row upon
initialization and when the row to be colored is selected it will set
the text of the next row that is selected instead of the selected row.
Here is a sample applet generated by NetBeans:
/*
* TestColorsTree.java
*
* Created on August 15, 2003, 8:51 AM
*/

/**
*
* @author Jim Katz
*/
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.JTree;
public class TestColorsTree extends javax.swing.JApplet {

/** Initializes the applet TestColorsTree */
public void init() {
renderer = new defaultRenderer();
initComponents();
}
private defaultRenderer renderer = null;
/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTree1 = new javax.swing.JTree();

getContentPane().setLayout(null);

jTree1.setCellRenderer(renderer
);
jScrollPane1.setViewportView(jTree1);

getContentPane().add(jScrollPane1);
jScrollPane1.setBounds(82, 38, 160, 182);

}
public class defaultRenderer extends
javax.swing.tree.DefaultTreeCellRenderer {
public defaultRenderer(){
}
public java.awt.Component getTreeCellRendererComponent(
JTree jTree1,
Object value,
boolean sel,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
super.getTreeCellRendererComponent(jTree1, value,
sel,expanded, leaf, row,hasFocus);
this.setTextNonSelectionColor(new java.awt.Color(0,0,0));
String valString = value.toString();
String red = "red";
if ( leaf ){
if (valString.equals(red)){
this.setBackgroundNonSelectionColor(new
java.awt.Color(255,0,0)); // Make cell blue
this.setTextNonSelectionColor( new
java.awt.Color(0,255,0)); // set text to yellow ( this cell ONLY!)
}
else {
this.setBackgroundNonSelectionColor(new
java.awt.Color(255,255,255));
}
}
else {
this.setBackgroundNonSelectionColor(new
java.awt.Color(255,255,255));
this.setTextNonSelectionColor(new
java.awt.Color(0,0,0));
}
return this;
}
}
// Variables declaration - do not modify
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTree jTree1;
// End of variables declaration

}

Is there a flaw in my coding or should I report this as a Bug to Sun?

Thanks,

Jim

--
! Jim Katz
! Certified Clarion Developer
! Author: ABC DLL Toolkit Maintainer: DEF for ABC,DET for
Legacy
! Web Site: http://home.iag.net/~jimkatz/
! Company: iTradeZone,Inc.
! Using Clarion for Windows - Always looking for the simpler solution.
Jul 17 '05 #1
0 1955

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Piet | last post by:
Hi there, I have managed to write a small java program that display an xml file in a JTree. This was achieved by defining a suitable tree model. THe program works...somehow. The nodes (elements...
0
by: Sydney | last post by:
Hello, I have an editable JTree with a custom TreeCellRenderer (extends from DefaultTreeCellRenderer). I redefined the getTreeCellRendererComponent method, returning a JPanel in some case...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.