Reputation: 1170
I would like to make a jTable in which when user select an uneditable cell then it should change focus to the next editable cell automatically. Important: the user could select a cell by keyboard (tab or arrow) and by mouse clicking. Is it possible?? How to to it?
Upvotes: 0
Views: 2880
Reputation: 324137
Table Tabbing shows how you can do it with the keyboard.
I've never tried it but you should be able to use a MouseListener to invoke the same Action when you click on a cell.
Just did a quick test for the MouseListener and it seems to work fine:
JTable table = new JTable(...);
final EditableCellFocusAction action =
new EditableCellFocusAction(table, KeyStroke.getKeyStroke("TAB"));
MouseListener ml = new MouseAdapter()
{
public void mouseReleased(MouseEvent e)
{
JTable table = (JTable)e.getSource();
int row = table.rowAtPoint(e.getPoint());
int column = table.columnAtPoint(e.getPoint());
if (! table.isCellEditable(row, column))
{
ActionEvent event = new ActionEvent(
table,
ActionEvent.ACTION_PERFORMED,
"");
action.actionPerformed(event);
}
}
};
table.addMouseListener(ml);
Upvotes: 1
Reputation: 332641
This link details Programmatically Making Selections in a JTable Component; you'd have to have mouselisteners/etc chained to work off this.
Upvotes: 1