2

我试图创建一个Jtree使用多个单独的图标(每个不同的图标node

我尝试了多种解决方案,但其中任何一个都确实完成了工作。很多只是改变“ leaf,,isClosed等”options

ImageIcon pointer;

(INSIDE public Component getTreeCellRendererComponent(..){

DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
int nodeLevel = node.getLevel();

switch(nodeLevel){

case 0: { pointer = new ImageIcon(///PATH///)
setIcon(pointer);
break;

case 1: { if(here i check some condition to get an specific amount of nodes){
pointer = new ImageIcon(///PATH2///); // this is a dynamic path. changes with a variable
setIcon(pointer);
}
else{
if(now i check for a specific node){
pointer = new ImageIcon(///PATH3///); // this is a dynamic path. changes with a variable
}

//there are more if's here, but the same situation applies

break;
}

我希望渲染器将图标应用到指定的节点(我用 if 得到的),但它只是将选择的最后一个图标应用到应该已经修改的所有先前节点。其他所有解决方案都是这样结束的:/。谢谢你的时间

4

0 回答 0