📄 categorytreecellrenderer.java
字号:
package net.robin.crm.ui;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import net.robin.crm.service.Category;
import net.robin.crm.service.Company;
public class CategoryTreeCellRenderer extends DefaultTreeCellRenderer {
private ImageIcon rootIcon;
private ImageIcon categoryIcon;
private ImageIcon companyIcon;
// private boolean hasFocus;
//
public CategoryTreeCellRenderer() {
super();
}
public Component getTreeCellRendererComponent(
JTree tree,
Object value,
boolean sel,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,
row, hasFocus);
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
Object userObject = node.getUserObject();
//处理根节点!
if (node instanceof CategoryRootTreeNode) {
if(rootIcon!=null){
setIcon(rootIcon);
}
}
if (userObject instanceof Category) {
if(categoryIcon!=null){
setIcon(categoryIcon);
}
}
if (userObject instanceof Company) {
if(companyIcon!=null){
setIcon(companyIcon);
}
}
// this.hasFocus = hasFocus;
return this;
}
// public void paint(Graphics g) {
// super.paint(g);
//
// if(hasFocus)
// g.drawString("选定了!", 0, 15);
// }
//
public ImageIcon getCategoryIcon() {
return categoryIcon;
}
public void setCategoryIcon(ImageIcon categoryIcon) {
this.categoryIcon = categoryIcon;
}
public ImageIcon getCompanyIcon() {
return companyIcon;
}
public void setCompanyIcon(ImageIcon companyIcon) {
this.companyIcon = companyIcon;
}
public ImageIcon getRootIcon() {
return rootIcon;
}
public void setRootIcon(ImageIcon rootIcon) {
this.rootIcon = rootIcon;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -