• Post Reply Bookmark Topic Watch Topic
  • New Topic

add JFormattedTextField as nodes on a JTree

 
Brian Brian
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone have an example of how to add JFormattedTextFields
or even JTextFields into a JTree. When adding nodes I want to pass
the text to initialize the text fields. With this text I can
appropriately construct masked text fields for users to modify.
I will then loop through the JTree with the modified nodes and save the
data into a database.
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Brian.
Look at Creating a tree from The Java Tutorial
A node in a tree is represented by an instance of DefaultMutableNode. Its toString method returns the string obtained from toString on the object that DefaultMutableNode encapsultes.
You can use a TreeCellRenderer to render the cells of a tree. DefaultTreecellRenderer.getRendererComponent() can be used to return the label that will render each cell. Tipically calling toString on the corresponding DefaultMutableNode.
You do not need to assigned a JFormattedTextField to each node for checking input. Use a DefaultCellEditor with a given JFormattedTextField that will check the input for all the nodes in the tree:
"tree.setCellEditor(new DefaultCellEditor(
new JFormattedTextField(new SimpleDateFormat("h:mm a"))));"
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!