Solved

Tree cell editing

Posted on 2004-08-18
12
299 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
fibonacci ten numbers 4 54
Bot application - advice 3 58
project copy paste issue 1 61
Java Eclipse Loop 3 28
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.

685 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