Solved

Tree cell editing

Posted on 2004-08-18
12
294 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

746 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