Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Focus issues with JCheckBoxes in a JTable



Bill Tschumy wrote:

I have a JTable that has a column with Boolean values. This column is set to be editable and I use the default cell editor which is a JCheckBox. I find that after clicking a checkbox, my menu shortcuts no longer work until I click elsewhere to move the focus away from the checkbox. Note that this only happens if I set the JTable as a whole to be non-focusable (so I don't get selection rectangles when I click in a cell).

Which version of Java is this? I don't see that problem in my app on Java 1.3.1.



I have one work around where in the tableChanged() notification I set the focus back to the main window. However there is a timing issue where I need to delay transferring the focus using invokeLater in order to get it to work. There is also an issue in that I need to do this only if the change is the result of a click (i.e. it is non- programmatic). This requires me to set some flags before and after the programmatic changes. Overall, this solution seems a bit messy and I'm wondering if others have encountered it and found a better way.


You could create your own cell editor and handle the transfer of focus in it. That would resolve the issue with programmatic changes. You'll probably have to experiment to figure where the best place to do that is. Just off the top, I would guess stopCellEditing() and cancelCellEditing() would be the places to start. I've had some trouble with stopCellEditing() getting called at odd times, so if doesn't work, you may be able to do it in getCellEditorValue() instead (or in addition).

Rob
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >Focus issues with JCheckBoxes in a JTable (From: Bill Tschumy <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.