Reputation: 608
I am trying to highlight the focus movement in the JTable
through this code:
if(e.getKeyCode() == (KeyEvent.VK_TAB)){
int prevRow;
int row = table.getSelectedRow();
int col = table.getSelectedColumn();
if(col == 0) {
System.out.println(row);
MinMax val = null;
TableCellRenderer currRend = table.getCellRenderer(row,col);
val = (MinMax) table.getValueAt(row, col);
JComponent comp = (JComponent) currRend.getTableCellRendererComponent(table, val, false, false, row,col);
comp.setBorder(BorderFactory.createLineBorder(Color.RED));
table.requestFocus(true);
}
The scenario is this, when I press TAB for the first time the second row is selected, initially the focus is set on row[0], the border is not painted, when I press the second time the third row is selected highlighting both 2 and 3rd row.
After that whenever tab is pressed, the highlighting of the border becomes relevant to the row selection.
I am facing issue when I am running the application under normal mode and not under de-bugger mode with break points.
Upvotes: 0
Views: 127
Reputation: 109813
There no reason for bothering with KeyEvents
from KeyListener
, if not generated some extra special Events
, implements prepareRenderer
, and there you have to test if is isSelected()
or hasFocus()
, I think that everything and nothing better around as @camickr's Table Row Rendering,
Upvotes: 1