This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Sharing document between JTable Cells and JTextFields Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Sharing document between JTable Cells and JTextFields" Watch "Sharing document between JTable Cells and JTextFields" New topic
Author

Sharing document between JTable Cells and JTextFields

Ste Graham
Greenhorn

Joined: Sep 15, 2003
Posts: 23
Hi - in my GUI I have a JTable which lists the records in a database. Below the JTable there is a group of JTextFields which act as a "form" for individual database records. So, for example, you click on a row within the JTable and the individual record is displayed within the JTextFields.

The problem I am having is getting the record in the JTextField format and the (same) record in the JTable row to update when one of the ways is used for updating. I think I have two ways to handle this:

1. The users decided which way they want to update the record (either using the JTable or the JTextFields), and when they hit the "Update Record" button the databses is updated, the TableModel is updated to reflect the change and the new TableModel is now used to show the data in the JTable and the JTextFields.

2. I share the underlying document between the JTextFields and the Cells in the JTable, so when I type in the JTextField the data is automatically typed in the cell and vice-versa.

I've tried both ways, but without much success. The problem I have with the first one is, if the "Update" button is the same for both JTextFields and JTable (which it is) how do I know which value I should use to update the databases with - the JTable value or the JTextField one?

For the second way, I'm unsure the best way to go about it. Do I need to create new DefaultCellEditor objects with JTextField objects, so I then can use the getDocument/setDocument methods? I tried something like:



This doesn't see to work as expected and only works one way when it does work.

As anybody expereinced this before? Any soultions, tips etc.

Cheers, Stephen
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sharing document between JTable Cells and JTextFields
 
Similar Threads
Regarding Jtable row Deletion
JTable problem
JTable, JTextField and focus
JTable with different objects (or components) in a column
JTable ........