I am using JTable. I need suggestion regarding following. Please help me out.
I need suggesgtion that at background what should i use to know that a particular row is added,edit,delete or a certain operation is done.
All the following operation are done after clicking Edit Button.
1. I have add button to add row into jTable.
2. I have edit button to edit a particular row. And there is another column that shows that if "YES" is selected then only "YES" option value are updated. Is this correct.....???
3. I have delete button to remove a particular row. How do i know if 3 rows are deleted randomly out of 10 rows. (Shoud i use vector or something else)
4. What if Row # 3 is deleted and another Row is added at last. How do i know that which row is added as total rows are 10 in both cases (delete/add row).
5. How do i know that particular row is edited. Let column 1 has code = 1001 and that column value is now change to 1002. (I think i can get this from YES option as i defined in Q#2.) Is this correct.
Please help me what technique should i use to handle my all required events. Answer me if you can help me out regarding any of above scneario.
Thanks in advance.
Love is GOD and GOD is Love.<br /> <br />Anand Karia<br />Manager I.T<br />Artistic Garment Ind. Pvt. Ltd<br />MSC (Computer Science)
Joined: Apr 28, 2004
This is rather tough. Firstly I can't say I understand your question, especially the second paragraph. I can try giving you a few of tips though:
1) Read Swing tutorial for JTables (google for java swing jtable tutorial). 2) Implement a proper table model. 3) Implement a table model listener. (There are sections discussing these issues in the tutorial) 4) Post questions concerning Swing to Swing forum. 5) Remember that MVC has a lerning curve.
Best regards, Petr
Get a better web browser:<br /><a href="http://www.mozilla.org/products/firefox/switch.html" target="_blank" rel="nofollow">http://www.mozilla.org/products/firefox/switch.html</a>
Joined: Aug 07, 2003
Assumption: You are presenting a bunch of data rows in the table, letting the user add/edit/delete them at will, and then saving all the changes at once (e.g. with a save button).
Given this pattern, you'll want to create a table model that tracks the changes the user makes for saving later. One method I've found useful is to maintain two extra collections along with the basic model: addedItems and removedItems.
When the user edits a row, either set up the row items to track this with a boolean or add a third collection to the model: editedItems.
Then, as the user makes changes, add the row items to the appropriate collection. Make sure the collection doesn't allow duplicate rows (you can't delete the same item twice).
When it's time to save the changes, either bundle them all up to send elsewhere (to an EJB or remote service or whatever) or apply the changes directly, collection-by-collection, row-by-row. Off the top of my head, in the past I'd delete items, then update items, then add items. This order allows the most likely combinations to occur naturally.
For example, starting with rows A, B and C, the user can delete row B, change row C to B, and add a new row C without problems. Of course, this can vary depending on your method of saving and the standard use cases.
As for the JTable (the view), it listens for various table-modification messages from your model. Therefore, your code (the controller) that responds to add/delete button presses and cell updates should operate on the model itself, and the table will repaint appropriately. [ November 04, 2004: Message edited by: David Harkness ]