setFont(getFont().deriveFont(Font.BOLD));
public TreeNode[] getPathToRoot(TreeNode aNode);
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;
/**
* The type TreeIconRenderer is responsible for changing the tree icons.
*
* @author smokie */
public class TreeIconRenderer extends DefaultTreeCellRenderer {
// declaring the Icons
Icon leafIcon;
ImageIcon openIcon;
ImageIcon closedIcon;
public TreeIconRenderer() {
super();
// getting image box
leafIcon = new ImageIcon(getClass().getResource("/images/system/box.gif"));
// getting image arrow down
openIcon = new ImageIcon(getClass().getResource("/images/system/arrow_down.gif"));
// getting image arrow right
closedIcon = new ImageIcon(getClass().getResource("/images/system/arrow.gif"));
}
/**
* Creating the component in the GridBagLayout.
*
* @param tree tree
* @param value cell value
* @param selected closed tree icon
* @param expanded opened tree icon
* @param leaf end point icon
* @param row number of row
* @param hasFocus the focus
*/
public Component getTreeCellRendererComponent(
JTree tree,
Object value,
boolean selected,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
super.getTreeCellRendererComponent(
tree, value, selected,
expanded, leaf, row,
hasFocus);
// setting icons
setLeafIcon(leafIcon);
setOpenIcon(openIcon);
setClosedIcon(closedIcon);
setBackgroundSelectionColor(new Color(0, 0, 128));
putClientProperty("JTree.lineStyle", "None");
// setFont(getFont().deriveFont(Font.BOLD));
setBackground(new Color(212, 217, 231));
return this;
}
}
package de.weidmueller.view;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.tree.*;
/**
* The type TreeIconRenderer is responsible for changing the tree icons.
*
* @author smokie */
public class TreeIconRenderer extends DefaultTreeCellRenderer {
// declaring the Icons
Icon leafIcon;
ImageIcon openIcon;
ImageIcon closedIcon;
public TreeIconRenderer() {
super();
// getting image box
leafIcon = new ImageIcon(getClass().getResource("/images/system/box.gif"));
// getting image arrow down
openIcon = new ImageIcon(getClass().getResource("/images/system/arrow_down.gif"));
// getting image arrow right
closedIcon = new ImageIcon(getClass().getResource("/images/system/arrow.gif"));
}
/**
* Creating the component in the GridBagLayout.
*
* @param tree tree
* @param value cell value
* @param selected closed tree icon
* @param expanded opened tree icon
* @param leaf end point icon
* @param row number of row
* @param hasFocus the focus
*/
public Component getTreeCellRendererComponent(
JTree tree,
Object value,
boolean selected,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
super.getTreeCellRendererComponent(
tree, value, selected,
expanded, leaf, row,
hasFocus);
// setting icons
setLeafIcon(leafIcon);
setOpenIcon(openIcon);
setClosedIcon(closedIcon);
setBackgroundSelectionColor(new Color(0, 0, 128));
putClientProperty("JTree.lineStyle", "None");
TreePath selectionPath = tree.getSelectionPath();
TreePath nodePath = new TreePath(((DefaultTreeModel)tree.getModel()).getPathToRoot((TreeNode)value));
if(selectionPath != null && (selectionPath.equals(nodePath) || nodePath.isDescendant(selectionPath))) {
setFont(getFont().deriveFont(Font.BOLD));
}
setBackground(new Color(212, 217, 231));
return this;
}
}
package de.weidmueller.view;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.tree.*;
/**
* The type TreeIconRenderer is responsible for changing the tree icons.
*
* @author smokie */
public class TreeIconRenderer extends DefaultTreeCellRenderer {
// declaring the Icons
Icon leafIcon;
ImageIcon openIcon;
ImageIcon closedIcon;
public TreeIconRenderer() {
super();
// getting image box
leafIcon = new ImageIcon(getClass().getResource("/images/system/box.gif"));
// getting image arrow down
openIcon = new ImageIcon(getClass().getResource("/images/system/arrow_down.gif"));
// getting image arrow right
closedIcon = new ImageIcon(getClass().getResource("/images/system/arrow.gif"));
}
/**
* Creating the component in the GridBagLayout.
*
* @param tree tree
* @param value cell value
* @param selected closed tree icon
* @param expanded opened tree icon
* @param leaf end point icon
* @param row number of row
* @param hasFocus the focus
*/
public Component getTreeCellRendererComponent(
JTree tree,
Object value,
boolean selected,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
super.getTreeCellRendererComponent(
tree, value, selected,
expanded, leaf, row,
hasFocus);
// setting icons
setLeafIcon(leafIcon);
setOpenIcon(openIcon);
setClosedIcon(closedIcon);
setBackgroundSelectionColor(new Color(0, 0, 128));
putClientProperty("JTree.lineStyle", "None");
TreePath selectionPath = tree.getSelectionPath();
TreePath nodePath = new TreePath(((DefaultTreeModel)tree.getModel()).getPathToRoot((TreeNode)value));
if(selectionPath != null && (selectionPath.equals(nodePath) || nodePath.isDescendant(selectionPath))) {
setFont(getFont().deriveFont(Font.BOLD));
}
else setFont(getFont().deriveFont(Font.PLAIN));
setBackground(new Color(212, 217, 231));
return this;
}
}