aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Restrict Editing the node in JTree on reaching its maximum length Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Restrict Editing the node in JTree on reaching its maximum length" Watch "Restrict Editing the node in JTree on reaching its maximum length" New topic
Author

Restrict Editing the node in JTree on reaching its maximum length

Suganthi Velliah
Greenhorn

Joined: Apr 30, 2007
Posts: 17
Hi All,

I have a doubt in JTree.

I have a Tree structure as follows:

Parent1
|
Child 1
Child 2
Child 3

Where I get popup on right click of the node with options Add, Remove & Rename. So I can rename the node. The node name’s length should be <=16 characters. So while renaming the node, I want to stop the keystrokes if it reach 16 characters.

Do you have any idea to do this?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10376
    
    8

Check out DocumentListener or DocumentFilter API.
Essentially you need to provide a custom DocumentXXX to the JTextField which the user is using to edit the name.

To get a rough idea on how it should be done check this out http://faq.javaranch.com/java/NumericTextField


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Suganthi Velliah
Greenhorn

Joined: Apr 30, 2007
Posts: 17
Thanks Maneesh

I have solved the problem.

We already have cutomized JTextField for restricting the keystrokes once it reaches the maximum length.

I have done as follows:

MyTextField textField = new MyTextField(16);
TreeCellEditor editor = new DefaultCellEditor(textField);

tree.setEditable(true);
tree.setCellEditor(editor);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Restrict Editing the node in JTree on reaching its maximum length