Re: JTable and input methods (or, and: focus in JTextField)



Ok, I suppose that was sloppy language. I get an exception, but in
system level code (not one entry in the stack trace is from my own
code).

Anyway, I found a way to fix it, which I thought I'd share :-) : I
redefined changeSelection in JTable:

public void changeSelection(int rowIndex, int columnIndex, boolean
toggle, boolean extend)
{
super.changeSelection(rowIndex, columnIndex, toggle, extend);

if(editCellAt(rowIndex, columnIndex))
getEditorComponent().requestFocusInWindow();
}

In other words, as soon as the other clicks on a cell or tabs to a cell
using the keyboard, the cell is immediately put into edit mode and gets
focus. Thus, when the input method is used, the active component
accepts text input and everything is fine.

I first tried to override editCellAt() instead, by doing something like

public boolean editCellAt(int row, int column, EventObject e)
{
boolean r = super.editCellAt(row, column, e);
if(r)
getEditorComponent().requestFocusInWindow();
return r;
}

But that doesn't _quite_ work: when the user types the first character
in a cell, editCellAt gets invoked, and the textfield that is
responsible for editing the cell then receives focus. Unfortunately,
that is only _after_ the first character, so you still get an exception
on the first character.

Edsko

.



Relevant Pages


Loading