JTree node Rename
I am using a JTree and in this to raname a JTree node I am using right click(Rename through popup) or F2 key or double click. But problem is : when I rename a name and hit Enter key, node successfully renamed and when I ren开发者_如何学JAVAame a name and click anywhere on the frame(windows explorer style), node name does not rename.
Please give me a solution for this problem and Thanks in advance.
It's probably a little late, but the correct solution is to call JTree.setInvokesStopCellEditing(true)
. This will cause the tree to execute the rename when the user hits enter, or when the cell editor loses focus.
The ability to save the current edit by clicking elsewhere in the tree is not something that comes standard as part of the default JTree
implementation. You're going to have to get into the details of how to use trees and do some special customization in order to achieve this functionality. This sounds like it would involve something with the focus of Swing components, i.e., when the tree gains focus, if the node is being edited, then save the node rename.
精彩评论