JTable and JTextField

Hello,

I have a problem with JTable and JTextFields on it. I have an FocusAdapter that listens

for events from JTextField.

publicclass MyFocusAdapterextends FocusAdapter{

public MyFocusAdapter(){

}

publicvoid focusLost(FocusEvent e){

JTextField field = (JTextField) e.getSource();

field.setText("23,23;23,12");

}

}

This is the code that i use to add text field to the table,

TableColumn column = jTable1.getColumnModel().getColumn(0);

column.setCellEditor(new DefaultCellEditor(field));

But when i loose focus from 1 cell in the table, method is invoked but the value is not updated. Any ideas how to do this on the right way ?

[1138 byte] By [Matrix_Na] at [2007-11-27 5:59:49]
# 1
Would repaint() help?
rebola at 2007-7-12 16:36:53 > top of Java-index,Desktop,Core GUI APIs...
# 2
I don't think that this will help in this situation.
Matrix_Na at 2007-7-12 16:36:53 > top of Java-index,Desktop,Core GUI APIs...
# 3
You don't THINK so... OK.So what happens? If you mess around in the application a bit, does the text show up after a while, or does it never show up at all?
rebola at 2007-7-12 16:36:53 > top of Java-index,Desktop,Core GUI APIs...
# 4
Oh, I have forgot to paste the initialization of the Field.JTextField field = new JTextField();field.addFocusListener(new MyFocusAdapter());
Matrix_Na at 2007-7-12 16:36:53 > top of Java-index,Desktop,Core GUI APIs...
# 5
Does never show up.
Matrix_Na at 2007-7-12 16:36:53 > top of Java-index,Desktop,Core GUI APIs...
# 6
Now i got a progress. When i edin a cell in a JTable and click on the some other component that is not in a JTable value is updated.
Matrix_Na at 2007-7-12 16:36:53 > top of Java-index,Desktop,Core GUI APIs...
# 7
So focusLost() isn't called before the JTable looses focus. There's your problem. Read some documentation about focus: http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html and see if that helps.
rebola at 2007-7-12 16:36:53 > top of Java-index,Desktop,Core GUI APIs...
# 8

I have no idea what you are attempting to do. I don't understand what your focus lost method is trying to do. You are using the text field as an editor. When you edit a cell in a table then the value from the TableModel is displayed in the editor. When you stop editing a cell the value in the editor is saved to the table model.

camickra at 2007-7-12 16:36:53 > top of Java-index,Desktop,Core GUI APIs...