Please Help: Renaming a Node In JTree
Hi All-
I'm new to Swing, and am havingsome luck with this, but am running into a little issue that I'm not sure what is causing it... I am renaming a node in my JTree (which is working successfully), however, when the new name is being displayed, it is being displayed with a blue dot on the left side of it (probably indicating it's a node?) -- which Ido not want! How can I get rid of this? I would be really appreciative if some experience eyes could look at this and tell me where I'm going wrong...
Here is my code:
private void btnRenameIconActionPerformed(java.awt.event.ActionEvent evt) {
TreePath currentSelection = treeIcons.getSelectionPath();
if (currentSelection != null){
//Message box confirming renaming
int result = JOptionPane.showConfirmDialog(null, "Are you sure you want to rename the" +
" selected icon or category?", "Rename", JOptionPane.YES_NO_OPTION);
//If 'YES' -> Allow user to rename the selection
if(result == JOptionPane.YES_OPTION){
String newName = (String)JOptionPane.showInputDialog(null, "Input the new name:", "Rename", JOptionPane.PLAIN_MESSAGE);
DefaultMutableTreeNode lastNode = (DefaultMutableTreeNode)
(currentSelection.getLastPathComponent());
MutableTreeNode parent = (MutableTreeNode)(lastNode.getParent());
if (parent != null){
final String categoryName = lastNode.toString();
lastNode.setUserObject(newName);
}
DefaultTreeModel model = (DefaultTreeModel)treeIcons.getModel();
((DefaultTreeModel)treeIcons.getModel()).nodeChanged(lastNode);
return;
}
//If 'NO' -> -> Return to Icon Manager window
else{
return;
}
}
// If there was no selection
JOptionPane.showMessageDialog(this, "No icon or category was selected!");
}
Thanks in advance for your help, it is very much appreciated!!
-Jeanna

