This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Restrict Editing the node in JTree on reaching its maximum length  RSS feed

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Suganthi Velliah
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!