Solved

Tree cell editing

Posted on 2004-08-18
12
296 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

773 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