• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTree with multiple editor types

 
Ken Gentry
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using a JTree in my GUI. In the data model there are four types of leaf nodes - text, numeric, date/time and enumeration. I want to have a simple text field editor for the text and numeric, a JSpinner widget for date/time editing and JComboBox for enumerations. I see tons of examples where one editor type is specified. Can I specify three different editor classes for a JTree?

Any ideas on this are greatly appreciated,
Ken
 
Fred Kleinschmidt
Bartender
Posts: 458
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TreeCellEditor is an interface with only one method: getTreeCellEditorComponent.
That method takes the leaf and row as input parameters; you can create your own extension of TreeCellEditor and create the three different editors as instance variables. then your getTreeCellEditorComponent() method just calls the appropriate one of those editors based on the leaf and row.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!