[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Changing a value in my Arraylist

Posted on 2011-10-28
10
Medium Priority
?
246 Views
Last Modified: 2012-05-12
now I have a dialog box getting the users comment.  I need to figure out how change the value in my arraylist.

I am thinking it would be something like

 public void commentSelectedRow(int row, String comment) {
         boolean b = (rds.set) != null);
        
        
   }
I know that set is looking for what value you want to change and the new value

rds.set(value, comment);

row is the index in the arraylist I want to add the value to

I need to know how to change the value in the last spot - example

row would be equal to tcRevision, tcSelected, tcComment

how do I only change tcComment??

rds.set(row.getTcComment(), comment);  ??

0
Comment
Question by:jkteater
  • 4
  • 4
  • 2
10 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 500 total points
ID: 37046717
But you added the comment as a new field of RevDataset. You should be setting the value on an object of that type and letting the classes that are clients of/consuming RevDataset instances handle displaying the new value
0
 

Author Comment

by:jkteater
ID: 37046795
Basically what I have and this could be exactly what you are talking about above.

In my table, which is a display of what the user selects and adds to the ArrayList.  Well now at the end of the table there is column named comments and by default it is a null field.  I have added a button to the dialog that will take the selected row in the table and pop up a dialog

public void commentTableRow() {
	   int row = selectTable.getSelectedRow();
   	   comment = JOptionPane.showInputDialog(null, "Please Enter Your Comment");
	   myModel.commentSelectedRow(row, comment);
   } 

Open in new window


I am basically wanting to get the value of the comment the user typed in and the row (index of the arraylist )
I want to update the null comment with the value to the user typed in.  So in the commentSelectedRow(row, comment); method I am trying to pass in the row (index) and the comment.  Then in the Arraylist change the vlaue from NULL to what the user typed in then update the table to show the comment.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 37046802
You need to update the value at its *source* (which is in the RevDataset instance)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jkteater
ID: 37046883
The popup dialog is in class 3 do I need to make a instance of class 3 in the RevDataset class, so I can get the comment value?  I am trying to figure out how to update the value
0
 

Author Comment

by:jkteater
ID: 37047119
Can you please step me though how you think the value should be getting updated.  I am have tried many things and I am only getting more confused as I go.  Heck I am not even sure I can change the value any more.

This is what I tried last

I have a method in RevDataset called

   public String getRevComment() {
       return rComment;
   }// end RevComment()

Open in new window


I call that function when creating the table atValue

 case COMMENT_COL: { o = rds.get(row).getRevComment(); break; }

so I thought if I get the comment value and somehow assign it where rComment is equal to the user comment then call a firetable, it would show the updated value.  But that does not work, for one reason it wants to add the value to all the selections and not just the one.

I will increase the points, I really need help with this one.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 37049378
btw, i think you might like to consider taking a step back to go forward better. Instead of just adding a String comment member to RevDataset, it would be stronger and more reusable to add a Map instead. That way, you could add any number of extra bits of data to RevDataset at any time and have them reflected in your table. What do you think?
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 37052458

I recall you base your table on the ArrayList of custom objects, each of which encompasses two other custom objects and one of those is basically the
the set of properties - am I right in that impression?
If so, can't you add one more property to that class which would correspond to the Comment and would be null at the beginning
and will be assigned value through this JOptionPane which will be popping up on on clicking the row?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37052472
Please, remind, what are the objects which make up elements in your ArrayList ?
Perhaps, post the class to which the elements of your ArrayList belong.
0
 

Author Comment

by:jkteater
ID: 37057173
I did get this working over the weekend.  I basically was able to find the field by using the selected row index and assigning the user comment to the null value.  

I will split the points and I do appreciate your time and effort in helping me.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 37057357
>>I will split the points and I do appreciate your time and effort in helping me.

I don't understand why that's the 'accepted solution' but thanks anyway
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month17 days, 15 hours left to enroll

829 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