1.用到的类: JTree , DefaultMutableTreeNode, DefaultTreeCellRenderer
2.默认情况下节点显示的是DefaultMutableTreeNode对象的setUserObject(Object obj)中obj的toString方法的返回值。
3.写个类继承DefaultTreeCellRenderer,重写getTreeCellRendererComponent方法就可以了。
4.结果如图:
5.代码
1.User类
package lova.tree.pojo;
public class User {
private String account; //账号
private String signature;//签名
private String iconPath;//头像路径
public User(String account,String signature,String iconPath){
this.account = account;
this.signature = signature;
this.iconPath = iconPath;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getSignature() {
return signature;
}
public void setSignature(String signature) {
this.signature = signature;
}
public String getIconPath() {
return iconPath;
}
public void setIconPath(String iconPath) {
this.iconPath = iconPath;