Menu

#239 Problem with focus listener in insert/edit mode when writing

v1.0_(example)
open
nobody
None
5
2013-09-27
2013-09-27
Lukas Voves
No

Hello, I found a bug in focusing next column in grid when you are in insert/edit mode and you are changing values. If you just go through the columns by hitting TAB, there is no problem. But if you write something in column and then hit TAB, there should be a problem in some situations. I have one example from my application. I have some columns that are editable and some that aren't (see attached picture). As you can see, I write something in first column and I hit TAB. After that I supposed to move to second column but it moved to fourth.
It is because of mistake in Grid class in method private void tabPressed(KeyEvent e).

There are bad indexes. I think that first column has index 0 but when I try to move to another column and get into this method, it shows me index 1. So when it wants to check next column which should be 1, it tests column 2.

Bad code:
if (colIndex + 1 == getColumnCount()
&& getSelectedRow() < model.getRowCount() - 1) {
colIndex = -1;
setRowSelectionInterval(getSelectedRow() + 1, getSelectedRow() + 1);
ensureRowIsVisible(getSelectedRow());
}
while (colIndex + 1 < getColumnCount() && !isCellEditable(getSelectedRow(), colIndex + 1)) {
colIndex++;
}
if (colIndex + 1 < getColumnCount()) {


Fix:
if (colIndex == getColumnCount()
&& getSelectedRow() < model.getRowCount() - 1) {
colIndex = -1;
setRowSelectionInterval(getSelectedRow() + 1, getSelectedRow() + 1);
ensureRowIsVisible(getSelectedRow());
}
while (colIndex < getColumnCount() && !isCellEditable(getSelectedRow(), colIndex)) {
colIndex++;
}
if (colIndex < getColumnCount()) {


1 Attachments

Discussion


Log in to post a comment.