• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jtable 2 columns (each column unique data)

 
Chris Syo
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Current Output:
ID        Names
A001      A001
A002      A002
A003      A003


Desired Output:
ID        Names
A001      John
A002      Manu
A003      Belo

How to add "Names" to the loop so it will display on the second column?

Thank you.
 
Campbell Ritchie
Sheriff
Posts: 51456
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can never remember hos tables work, but I can remember where to find something helpful in the Java™ Tutorials. That link will probably answer your questions.

Moving discussion to our GUIs forum.
 
Knute Snortum
Bartender
Pie
Posts: 2908
62
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(I've taken the liberty of formatting you code.)

You are adding the same thing (the ID) to columns one and two.  You need a way to access both the ID and the name in the same loop.  I would use a plain for-loop and then access the lists IDs and Names with the <list>.get(<index>) method.

Also, in the code above, you don't need String element = (String) object;, just use object, except that "object" is a bad variable name.  Use something more descriptive, like "id".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic