code: public static void applyButtonTreeCellRenderer(JTree tree, 
          Function<Object, JButton> buttonFactory,
          Function<Object, String> textFactory)
      {
          TreeCellRenderer treeCellrenderer = new GenericTreeCellRenderer()
          {
              @Override
              protected void prepare(Object nodeObject, JPanel container)
              {
                  container.setLayout(new BorderLayout(3, 0));
                  
                  JLabel textLabel = new JLabel();
                  String text = textFactory.apply(nodeObject); 
                  textLabel.setText(text);
                  container.add(textLabel, BorderLayout.CENTER);
                  
                  JButton button = buttonFactory.apply(nodeObject);
                  if (button != null)
                  {
                      container.add(button, BorderLayout.WEST);
                  }
              }
          };
          tree.setCellRenderer(treeCellrenderer);
          tree.setEditable(true);
          DefaultCellEditor editor = new DefaultCellEditor(new JTextField())
          {
              /**
               * Serial UID 
               */
              private static final long serialVersionUID = 1L;
              
              @Override
              public Component getTreeCellEditorComponent(JTree tree, Object value,
                      boolean selected, boolean expanded, boolean leaf, int row) 
              {
                  return treeCellrenderer.getTreeCellRendererComponent(
                      tree, value, selected, expanded, leaf, row, true);
              }
              @Override
              public boolean isCellEditable(EventObject event) 
              {
                  return true;
              }
          };
          tree.setCellEditor(editor);
      }
docs: Apply a cell renderer to the given tree that will create cells that
  consist of a button and a label, based on
  a {@link GenericTreeCellRenderer}.<br>
  <br>
  An editor will be installed for the tree, making the buttons
  clickable.<br>
  <br>
  Some details about the exact layout of the cells are intentionally
  not specified.
  
  @param tree The tree
  @param buttonFactory The factory that will receive the tree node,
  and return the JButton (to which listeners may already have been
  attached). If this function returns <code>null</code>, then no
  button will be inserted.
  @param textFactory The factory that will receive the tree node,
  and return the text that should be displayed as the node label.