Hi everybody,
I'm a having a problem with JTable. I have a JTable, created with a DefaultTableModel.
One of JTable's columns is editable. I've implemented it by setting a cellEditor in the column.
The cellEditor has a JTextField.
I need to select all the cell's value when it receives the focus (by a mouseClick or keyboard event).
When I do it in the mouseListener of the JTextField, it works, but in the FocusListener of the JTable, don't.
//MouseListener in JTextField: THIS WORKS
cellEditor.setClickCountToStart(1);
textField.addFocusListener(new FocusListener(){
public void focusGained(FocusEvent arg0) {
int column= table.getSelectedColumn();
int row = table.getSelectedRow();
if (column == 3){
DefaultCellEditor editor = (DefaultCellEditor)table.getColumnModel().getColumn(column).getCellEditor();
String valorCell = (String)editor.getCellEditorValue();
TextEMax textField = (TextEMax)editor.getTableCellEditorComponent(table, valorCell, true, row, column);
textField.selectAll();
}
}
public void focusLost(FocusEvent arg0) {
// TODO Auto-generated method stub
}
});
//Focus listener in JTable: THIS DOES NOT WORK
table.addFocusListener(new FocusListener(){
public void focusGained(FocusEvent focusevent) {
int row = table.getSelectedRow();
int column = table.getSelectedColumn();
if (column == 3){
DefaultCellEditor editor = (DefaultCellEditor)table.getColumnModel().getColumn(column).getCellEditor();
String valorCell = (String)editor.getCellEditorValue();
TextEMax textField = (TextEMax)editor.getTableCellEditorComponent(table, valorCell, true, row, column);
textField.selectAll();
}
}
public void focusLost(FocusEvent focusevent) {
// TODO Auto-generated method stub
}
});
Why it does not select the text in focusListener?? In which listener do i have to do it??
Thanks a lot, Guilherme