Link to home
Start Free TrialLog in
Avatar of mte01
mte01Flag for Lebanon

asked on

tableChanged event

In a JTable when the user enters data in a cell & leaves the cell (by pressing tab or something), the tableChanged event gets fired (if I have a TableModelListener added to the JTable), what if the user didn't leave the cell and pressed another button directly (for example a save button), then the data will not be saved in the JTable (and thus will not be retrieved in its getValueAt() function), so what can I do?

I was thinking of programmatically processing the TAB key by the following piece of code:

DefaultFocusManager fm = new DefaultFocusManager();
fm.processKeyEvent(jtablex,KeyEvent.VK_TAB); //where jtablex is an object of class JTable

The problem with this code is that KeyEvent.VK_TAB is an integer not a KeyEvent object (and there is no overloaded function to take a component and a KeyEvent object)
Avatar of mte01
mte01
Flag of Lebanon image

ASKER

An extra note is that the focus lost event would not work because the cell that the user is working on needs to lose focus (by pressing tab or something) not the JTable (which should still have the focus)
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mte01

ASKER

Amazing!! it did just the right thing.......although stopCellEditing is a boolean function (not a void) that I thought only returns whether the user has stopped editing or not. It seems that what it does is that it forces that editing of the JTable to get stopped programmatically, and thus the data that's edited gets saved.

Thank you very much...you really deserve it
8-)
Avatar of mte01

ASKER

I also have a few questions for you CEHJ...(I don't know if I am allowed to ask them by the moderator or not....). How old are you? Where do you live? How do you benefit from such programming expertise (i.e. what do you do in life)? What is the range of the amount of money that you can earn per month from such expertise? (I am asking this question because I am working on becoming one in the near future)

Thanks in advance