Solved

JTable row values repeatating after moving to next row.

Posted on 2013-01-15
7
377 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
Comment Utility
Please help

Regards
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
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
Comment Utility
Dear CEHJ,
I understood what you have observed. I will make it more appropriate.
Waiting for your sugestions.

Regards
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you very much for resolving my issue.

Regards
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
You're welcome.
Thanx 4 axxepting
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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.
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

743 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

19 Experts available now in Live!

Get 1:1 Help Now