Solved

JTable row values repeatating after moving to next row.

Posted on 2013-01-15
7
382 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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!

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

710 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