Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

tableChanged event

Posted on 2004-09-04
5
Medium Priority
?
551 Views
Last Modified: 2012-05-05
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)
0
Comment
Question by:mte01
  • 3
  • 2
5 Comments
 
LVL 3

Author Comment

by:mte01
ID: 11980287
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)
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 1800 total points
ID: 11981887
Try calling stopCellEditing on the cell editor first
0
 
LVL 3

Author Comment

by:mte01
ID: 11982410
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
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11982415
8-)
0
 
LVL 3

Author Comment

by:mte01
ID: 11982519
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
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question