Forums Register Login

Jtable 2 columns (each column unique data)

+Pie Number of slices to send: Send


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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
(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".
Does this tiny ad smell okay to you?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 620 times.
Similar Threads
Adding Column Dynamically to JTable
iscelleditable is not working in jtable
JTable
JTable
PASSING DATA IN A JTable
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 19:48:00.