B
Bumsys
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(filesLoadTreeCellRenderer);
} else {
treeFiles.setCellRenderer(filesNoLoadTreeCellRenderer);
}
}
}
}
}
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?
{
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(filesLoadTreeCellRenderer);
} else {
treeFiles.setCellRenderer(filesNoLoadTreeCellRenderer);
}
}
}
}
}
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?