-4

ここに画像の説明を入力 /* ツリー ノード (例: WEBLOGIC が選択されている) をクリックすると、ノード アイコンが消えますが、他のアイコン (選択されていない) が表示されます。この問題を解決するために私を助けてください。これはスイング ベースのプログラムです*/

class ColorRenderer extends DefaultTreeCellRenderer
{
  public ColorRenderer()
  {
    super();
  }

  public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
  {
    try
    {
      Component cell = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
      RTGTreeNode treeNode = (RTGTreeNode) value;
      GraphUniqueKeyDTO graphUniqueKeyDTO = treeNode.getGraphUniqueKeyDTO();

      /*Default Icon not needed.*/
      setIcon(null);

      if (graphUniqueKeyDTO == null)
      {
        return cell;
      }

      String nodeName = treeNode.toString();

      if (!leaf)
      {
        cell.setFont(NSColor.mediumPlainFont());
        if (selected)
        {
          cell.setForeground(Color.black);
          cell.setBackground(new Color(128, 0, 0));
        }
        else
        {
          Color color = treeNode.getNodeColor();

          if (treeNode.getTreeViewToolTip() != null)
            nodeName = treeNode.getTreeViewToolTip();
          openIcon = treeNode.getImgIcon();
          if(openIcon!=null){
              setIcon(openIcon);
              setLeafIcon(openIcon);

          }


          if(color == null)
            cell.setForeground(NSColor.leftPaneGroupTitleColor());
          else
            cell.setForeground(color);
        }
      }
      else
      {
        cell.setFont(NSColor.smallPlainFont());
        if (selected)
        {
          cell.setForeground(Color.black);
          cell.setBackground(new Color(128, 0, 0));
        }
        else
        {
          cell.setForeground(NSColor.leftPaneGraphTitleColor());
        }
      }

      setToolTipText(nodeName);
      JLabel currentCell = (JLabel) cell;
      currentCell.setHorizontalAlignment(JLabel.CENTER);
      return cell;
    }
    catch (Exception ex)
    {
      Log.errorLog("ColorRenderer", "getTreeCellRendererComponent", "", "", "Exception - " + ex);
      return null;
    }
  }
4

1 に答える 1