I have a custom TableCellEditor/AbstractCellEditor set up so that when the cell is double-clicked or the spacebar is pressed, it enters editing mode.
class TextAreaCellEditor extends AbstractCellEditor implements TableCellEditor {
JComponent component = new JTextArea();
@Override
public boolean isCellEditable(EventObject e) {
GenInput inp = new GenInput();
if (super.isCellEditable(e)) {
if (e instanceof MouseEvent) {
MouseEvent me = (MouseEvent) e;
return me.getClickCount() >= 2;
}
if (e instanceof KeyEvent) {
KeyEvent ke = (KeyEvent) e;
return ke.getKeyCode() == inp.spacebar; //'inp' is my own class that acts as a reference for keycodes
}
}
return false;
}
...
These both work, and activate StartEdit, which means that the following code is executed next:
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
int rowIndex, int vColIndex) {
((JTextArea) component).setText("");
((JTextArea) component).setWrapStyleWord(true);
((JTextArea) component).setLineWrap(true);
((JTextArea) component).requestFocus();
((JTextArea) component).addKeyListener(new KeyListener() {
...
Working Part: Regardless of whether or not I include "((JTextArea) component).requestFocus();" , when I double click it full enters editing mode, ie. the caret starts to blink, and when I press 'up' or 'down' the caret moves up and down in the multi-line textbox rather than skipping up or down to the next row.
Problem: However, when I press the spacebar it enters a sort of 'partial' editing mode; The result is that the caret doesn't blink, and while I can type words in the box, if I press 'up'/'down' it will jump to the previous/next row.
What can I do to make the caret appear (ie. enter 'full editing mode' as opposed to the 'partial editing mode' I've described) when I start editing via the spacebar?
Edit: "((JTextArea) component).getCaret().setVisible(true);" makes the caret show up, but doesn't change the fact that it is in a partial editing mode, so I still can't press up/down without losing focus.