Solved

JTable row values repeatating after moving to next row.

Posted on 2013-01-15
7
378 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now