Solved

JTable row values repeatating after moving to next row.

Posted on 2013-01-15
7
380 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
allswap challenge 6 99
runtime exception 2 30
null output 3 25
Delphi: barcode reading on android platform 1 34
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

825 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