Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > change icon in jtree

Reply
Thread Tools

change icon in jtree

 
 
Bumsys@gmail.com
Guest
Posts: n/a
 
      02-18-2008
private ActionListener changeFileIconLoadAction = new ActionListener()
{
public void actionPerformed(final ActionEvent e) {
getNameValueNode(true);
}
};

private TreeCellRenderer filesLoadTreeCellRenderer = new
DefaultTreeCellRenderer() {

public Component getTreeCellRendererComponent(final JTree
tree,
final Object value, final boolean selected,
final boolean expanded, final boolean leaf, final int
row,
final boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, selected,
expanded,
leaf, row, hasFocus);
if (value.toString().equals(nameNode)) {
setIcon(iconLoad);
setText(valueNode);
} else {
for (int i = 0; i < treeRoot.getChildCount(); i++) {
DefaultMutableTreeNode parent =
(DefaultMutableTreeNode) treeRoot
.getChildAt(i);
if (((TreeFile)
parent.getUserObject()).toString().equals(
value.toString())) {
setText(((TreeFile)
parent.getUserObject()).getPath());
}
for (int j = 0; j < parent.getChildCount(); j++) {
DefaultMutableTreeNode node =
(DefaultMutableTreeNode) parent
.getChildAt(j);
TreeFile tf = (TreeFile) node.getUserObject();
String fileName = tf.getPath();
if (tf.toString().equals(value.toString())) {
setText(fileName);
}
}
}
}
return this;
}
};

private ActionListener changeFileIconNoLoadAction = new
ActionListener() {
public void actionPerformed(final ActionEvent e) {
getNameValueNode(false);
}
};

private void getNameValueNode(boolean loading) {
nameNode =
treeFiles.getLastSelectedPathComponent().toString( );
for (int i = 0; i < treeRoot.getChildCount(); i++) {
DefaultMutableTreeNode parent = (DefaultMutableTreeNode)
treeRoot
.getChildAt(i);
for (int j = 0; j < parent.getChildCount(); j++) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
parent
.getChildAt(j);
TreeFile tf = (TreeFile) node.getUserObject();
String fileName = tf.getPath();
if (tf.toString().equals(

treeFiles.getLastSelectedPathComponent().toString( ))) {
valueNode = fileName;
if (loading) {

treeFiles.setCellRenderer(filesLoadTreeCellRendere r);
} else {

treeFiles.setCellRenderer(filesNoLoadTreeCellRende rer);
}
}
}
}
}

private TreeCellRenderer filesNoLoadTreeCellRenderer = new
DefaultTreeCellRenderer() {

public Component getTreeCellRendererComponent(final JTree
tree,
final Object value, final boolean selected,
final boolean expanded, final boolean leaf, final int
row,
final boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, selected,
expanded,
leaf, row, hasFocus);
if (value.toString().equals(nameNode)) {
setIcon(iconNotLoad);
setText(valueNode);
} else {
for (int i = 0; i < treeRoot.getChildCount(); i++) {
DefaultMutableTreeNode parent =
(DefaultMutableTreeNode) treeRoot
.getChildAt(i);
if (((TreeFile)
parent.getUserObject()).toString().equals(
value.toString())) {
setText(((TreeFile)
parent.getUserObject()).getPath());
}
for (int j = 0; j < parent.getChildCount(); j++) {
DefaultMutableTreeNode node =
(DefaultMutableTreeNode) parent
.getChildAt(j);
TreeFile tf = (TreeFile) node.getUserObject();
String fileName = tf.getPath();
if (tf.toString().equals(value.toString())) {
setText(fileName);
}
}
}
}
return this;
}
};
}

When I choose TreeCellRenderer filesLoadTreeCellRenderer the selected
node in jtree change icon, but if I choose TreeCellRenderer
filesNoLoadTreeCellRenderer the selected node in jtree change icon but
previously changings icon do not save. Why?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JTree Selection lost when JTree looses focus jumpz Java 3 11-12-2007 03:55 PM
change the icon of a JTree parent node according to its child nodes esamsalah@gmail.com Java 1 03-31-2005 02:07 PM
Change JTree background color. Nuno Paquete Java 1 02-27-2005 08:44 PM
app.rc resource's icon to .net Icon Miro Durcik ASP .Net 0 10-09-2004 12:44 AM
howto place internet icon on the level of the start icon Sieds Computer Support 5 04-18-2004 01:51 PM



Advertisments