• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

Tree cell editing

Hi,

I have a JTree - each cells can be 1 of 2 data-types - only one of these types is editable
 - is there a way of telling the editor this so that the editor will not be invoked for the un-editable type??
0
cathalmchale
Asked:
cathalmchale
  • 7
  • 5
1 Solution
 
girionisCommented:
Can you do something like:

if (<variable> instanceof <type you want>)
{
   // invoke editor
}
0
 
cathalmchaleAuthor Commented:
where abouts would u have this code??
0
 
girionisCommented:
Can you post the relevant code where you have your cell editor?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
cathalmchaleAuthor Commented:
for example this method in the editor:

public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row)

is called when a cell gets clicked, but its too late to do my checking data type here as the method insists a component is returned,
so I thought perhaps over-riding the isCellEditable method, but dont know how this would help??
0
 
girionisCommented:
You can always create your own cell editor and define the functionallity you want: http://javaalmanac.com/egs/javax.swing.table/CustEdit.html
0
 
girionisCommented:
Then put my pseudo-code inside the getTableCellEditorComponent. If the data type of the value passed is the one you want, do your processing and return the new value, otherwise return the same component.
0
 
cathalmchaleAuthor Commented:
>> You can always create your own cell editor

I have!!

Another question - is there a way of saying "Only start cell editing after a double click??"
 - i think i noticed this functionality in some component before??
0
 
cathalmchaleAuthor Commented:
>> otherwise return the same component

this is what i was doing.  It means returning an appropriate JLabel which doesnt look quite as good, and then it also means that i now have to handle the selection highlighting myself
0
 
girionisCommented:
The cell editor will be called anyway, no way to change that apart from locking the ceel (but then you wont be able to edit even the value you want). You will have to look to another solution like reading the call but ignoring the value passed. What happens if you return null? Is this acceptable?
0
 
cathalmchaleAuthor Commented:
>> What happens if you return null? Is this acceptable?

No.

But this double click routine is perfect - now for single click on cell editing isnt invoked (and JTree handles its own selection highlighting), for double click i handle the editing (and just return an appropriate JLabel for the data-type which isnt editable)

Thanks a lot for your help :)
0
 
girionisCommented:
Thank you for accepting, glad I was of help :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now