Solved

tableChanged event

Posted on 2004-09-04
5
530 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 450 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 Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now