Solved

Tree cell editing

Posted on 2004-08-18
12
295 Views
Last Modified: 2010-03-31
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
Comment
Question by:cathalmchale
  • 7
  • 5
12 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 11828756
Can you do something like:

if (<variable> instanceof <type you want>)
{
   // invoke editor
}
0
 

Author Comment

by:cathalmchale
ID: 11828763
where abouts would u have this code??
0
 
LVL 35

Expert Comment

by:girionis
ID: 11828804
Can you post the relevant code where you have your cell editor?
0
 

Author Comment

by:cathalmchale
ID: 11828830
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
 
LVL 35

Expert Comment

by:girionis
ID: 11828858
You can always create your own cell editor and define the functionallity you want: http://javaalmanac.com/egs/javax.swing.table/CustEdit.html
0
 
LVL 35

Expert Comment

by:girionis
ID: 11828906
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:cathalmchale
ID: 11828909
>> 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
 
LVL 35

Accepted Solution

by:
girionis earned 50 total points
ID: 11828922
0
 

Author Comment

by:cathalmchale
ID: 11828933
>> 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
 
LVL 35

Expert Comment

by:girionis
ID: 11828951
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
 

Author Comment

by:cathalmchale
ID: 11828981
>> 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
 
LVL 35

Expert Comment

by:girionis
ID: 11829012
Thank you for accepting, glad I was of help :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now