jtable and ctrl_down_mask
hi,
hope someone will give me some pointers to the following problem that i have.
i have a jtable that has 2 editable string columns.
i have a <keypress event> that handles <ctrl_down> and <space> keys when pressed simultaneously.
What i found was that when i tab into any of the columns initinially (field is selected when in focus), the <ctrl><space> event is picked up.
But, if i were to do some edit in the column and then press <ctrl><space>, the event does not get picked up.
Why ?
Thanks for any help
Tony
[611 byte] By [
tt_linuxa] at [2007-11-26 13:48:06]

# 1
Presumably the editing component handles and consumesKeyEvents.
# 2
the keyevents work ok. i was able to see my println() when the <ctrl><space> keys were pressed without doing any edits ...i am not sure where the keyevents went to when i start editing in the column.
# 3
> i am not sure where the keyevents went to when i start editing in the column. When editing a cell, a JTextField is used as the editor and has focus so it will receive the KeyEvents.When you are not editing a cell then the JTable has focus and it will receive the
# 4
is there a way to get at the keyevents when editing ?thanks for helping
# 5
Why do you want the KeyEvents? Typically you don't listen for KeyEvents. You would bind and Action for the KeyStroke or you would use a DocumentListener or a DocumentFilter.
Read the JTable API. There is a method to get the Default editor for the Object class. Once you have the editor you can get the editor component which for the default editor is a JTextField, so you cast it to a JTextField and add the appropriate Action or Listener.
# 6
all i want is really the ability to do the following:
1. user types some words in a column.
2. he may choose do autocomplete (by pressing <ctrl><space>. the abbreviated word in scope will then be automatically expanded to be some sequence of characters.
3. user then continues to type other words on the column ..
hence, my need to be able to do <ctrl><space> whenever the user chooses to during the edit stage.
i am new to this area hence, my question may be sound a little confused ...
should i be using a document listener or keystroke bind action ?
Any book u can recommend for a good read on this subject ?
# 7
Well first you should extend JTextField to support the functionality that you require. Its easier to test a simply text field then it is an editor in a table. Once this components works you would then create a new editor for the table using this component. See the DefaultCellEditor API. Then you would add this editor to the table.
I would use KeyBindings to handle the Ctrl+Space KeyStroke. Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html]How to Use Key Bindings[/url] for more information.
# 8
> Well first you should extend JTextField to support
> the functionality that you require. Its easier to
> test a simply text field then it is an editor in a
> table. Once this components works you would then
> create a new editor for the table using this
> component. See the DefaultCellEditor API. Then you
> would add this editor to the table.
>
did this already ... know how it works on a JTextField.
> I would use KeyBindings to handle the Ctrl+Space
> KeyStroke. Read the Swing tutorial on [url
> http://java.sun.com/docs/books/tutorial/uiswing/misc/k
> eybinding.html]How to Use Key Bindings[/url] for more
> information.
Would i be right to say that Keybinding for jtable can be used together with a DefaultCellEditor ?
Thanks for your info ... will read that article :)
# 9
> Would i be right to say that Keybinding for jtable can be used together with a DefaultCellEditor ?
No. The KeyBinding is added to the custom text field and the text field is used to create a cell editor.
The tutorial also has a section on "How to Use Tables" which show how to create a custom editor.
# 10
>
> No. The KeyBinding is added to the custom text field
> and the text field is used to create a cell editor.
>
> The tutorial also has a section on "How to Use
> Tables" which show how to create a custom editor.
Thanks. You save me from a lot of confusion. I was tearing my head over this issue for a while ...