Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

JTable row values repeatating after moving to next row.

Posted on 2013-01-15
7
Medium Priority
?
385 Views
Last Modified: 2013-01-21
Dear Experts,

I have one JTable. When so ever I move to next row, the values automatically updated by the values of last row.

Please help me in resolving the issue.
I am attaching the source code.

Regards
guestName.java
0
Comment
Question by:MILIND_JOG
  • 3
  • 2
  • 2
7 Comments
 

Author Comment

by:MILIND_JOG
ID: 38778419
Please help

Regards
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 38778629
I'll try to look at your code later. You need to make some alterations:

Java class names begin upper case, otherwise they look like method or variable names. You have a class called 'guestName' which takes in its ctor a String[] called 'guestName1'. That's confused and confusing.
0
 

Author Comment

by:MILIND_JOG
ID: 38778671
Dear CEHJ,
I understood what you have observed. I will make it more appropriate.
Waiting for your sugestions.

Regards
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 86

Expert Comment

by:CEHJ
ID: 38778686
I'll look at it later if i can. Also get rid of the 'magic numbers' in your code. How could the likes of
if(keycode == 119)

Open in new window

ever be seen as readable?? You will forget within a few days what that's meant to do
0
 
LVL 37

Accepted Solution

by:
zzynx earned 2000 total points
ID: 38786846
Change this:

       row = new Vector(3);
        for (int i = 0; i < guest_no; i++)
        {
            
            row.addElement(guestName[i][0]);
            row.addElement(guestName[i][1]);
            row.addElement(guestName[i][2]);
            data.addElement(row);
        }

Open in new window


into this

        for (int i = 0; i < guest_no; i++)
        {
            row = new Vector(3);  // <<<<<<< this line should be inside the loop
            row.addElement(guestName[i][0]);
            row.addElement(guestName[i][1]);
            row.addElement(guestName[i][2]);
            data.addElement(row);
        }

Open in new window


and your problem will be gone.

Explanation:
With your code the result of 'data' after the loop was:
data = { {A, 0, B, C, 1, D }, {A, 0, B, C, 1, D } }
with the corrected code it is:
data = { {A, 0, B }, { C, 1, D } }

Oh, and - as CEHJ - remarked:

for readability reasons, you'd better replace

if (evt.getKeyCode() == 119)

Open in new window

by
if (evt.getKeyCode() == KeyEvent.VK_F8)

Open in new window


and 'guestName1' by 'parameters'

Success!
0
 

Author Closing Comment

by:MILIND_JOG
ID: 38804303
Thank you very much for resolving my issue.

Regards
0
 
LVL 37

Expert Comment

by:zzynx
ID: 38804324
You're welcome.
Thanx 4 axxepting
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

971 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