I have a JTree cho has a renderer like that:
public class BrowserNodeRenderer extends DefaultTreeCellRenderer {
private JLabel label;
private JPanel panel;
private JLabel iconLabel;
private JTextField textField;
public BrowserNodeRenderer() {
this.panel = new JPanel();
final BorderLayout layout = new BorderLayout();
this.panel.setLayout(layout);
this.iconLabel = new JLabel();
this.label = new JLabel();
this.label.setOpaque(true);
//Unbold text
final Font f = this.label.getFont();
this.label.setFont(f.deriveFont(f.getStyle() & ~Font.BOLD));
this.panel.add(this.iconLabel);
this.panel.add(this.label, BorderLayout.CENTER);
}
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
//Editing label and icon depending on rules
//...
return panel;
}
}
When I right-click a node, a JPopup menu is displayed with an option to rename current node.
But I really do not know how to tell the node to display a textfield in place of the label to be edited.