Link to home
Start Free TrialLog in
Avatar of jkteater
jkteaterFlag for United States of America

asked on

What would be the best way to add a comment to a table entry

On my dialog form I have a jtable, the table is populated by user selections.  I need to give the user to add a comment about a selection on the table.  So i am thinking what if I create a array of strings and then I get the selected Row from the table - pop a comments dialog and save the typed string to the String Array at the index of the selected Row.  That way when I need to recall the information I can just run through the table list and the string array to get both information.  Does that sound OK?  Also I am wondering how I would show that a comment as been added.
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Do you happen to have a custom TableModel?
Avatar of jkteater

ASKER

abstractTableModel
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
I am using a class to format my arraylist.  

public class RevDataset {
	
	TCComponentItemRevision rev;
	TCComponentDataset componentdataset;
	
		
   //////////////////////////////////////////////////////////////////////////
   //                                                                      //
   //                              Constructor                             //
   //                                                                      //
   //////////////////////////////////////////////////////////////////////////
   public RevDataset(TCComponentItemRevision tcRevision, TCComponentDataset selectedDataset) {
      rev = tcRevision;
      componentdataset = selectedDataset;
   }// end Constructor
	
   //////////////////////////////////////////////////////////////////////////
   //                                                                      //
   //                              getDataset()                            //
   //                                                                      //
   //////////////////////////////////////////////////////////////////////////
   public TCComponent getDataset() {
      return componentdataset;
   }// end getDataset()

   //////////////////////////////////////////////////////////////////////////
   //                                                                      //
   //                              getRev()                                //
   //                                                                      //
   //////////////////////////////////////////////////////////////////////////
   public TCComponent getRev() {
      return rev;
   }//end getRev()
   
   
   //////////////////////////////////////////////////////////////////////////
   //                                                                      //
   //                              equals()                                //
   //                                                                      //
   //////////////////////////////////////////////////////////////////////////
   public boolean equals(Object o){
	     RevDataset p = (RevDataset) o;
	     if(rev.equals(p.getRev()) && componentdataset.equals(p.getDataset())) {
	        return true;
	     }
	     else { 
	        return false;
	     }	 
	}// end equals()
}

Open in new window


Then I am using a add method in a seperate class to build my List

 
 //////////////////////////////////////////////////////////////////////////
   //                                                                      //
   //                            add()                                     //
   //                                                                      //
   //////////////////////////////////////////////////////////////////////////
   public void add(TCComponentItemRevision tcRevision, TCComponentDataset selectedDataset){
     	   RevDataset pp = new RevDataset(tcRevision,selectedDataset);
	   if(!rds.contains(pp))rds.add(pp); 
	   fireTableDataChanged();
	  
   }// end add

Open in new window



If there a way to add a String value  to the RevDataset class so when the string is being built with the add method it would also be adding a null string to each one entry

the list would look something like
tcRevision, selectedDataset, comment

instead of

tcRevision, selectedDataset

That way the comment would be also available in the table
It wouldn't necessarily be a good thing to add it to the RevDataset class. Why don't you just add it when you build the TableModel?
Can you show me a example of to do that?
but also the user will be adding a comment to a specfic entry on the table.  If we add it to the table will we still be able to pull the information out?
The table IS the TableModel effectively. The only sense in which they differ is if/when you decide to hide columns from view. A JTable is just a view of a TableModel
You did answer the question and for that I thank you.  After learning more about what I was wanting, I understand that the question was not correctly asked.
:)

OK