Reading byte array into JTable using DefaultTableModel

Hi Experts,

I have an array of bytes that I want displayed in a JTable - very much like what a Hex Editor would display - every 16 bytes are displayed as a row in the table. The following are my questions:

1) How do I read every 16th Byte as a row in the JTable - ensuring the last cell is equivalent to the last byte in the array?
2) When I select a particular cell in the table how can I ensure I can obtain the equivalent byte in the array?
3) I have tried using a DefaultTableModel but I keep missing the last few cells in the array because the table only displays in rows of 16 if the array does not equate to an exact division of 16 I miss a row or I have an extra row in the table.
Juniper786Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

adrpoCommented:

You could pad the array with new zero elements to make it a multiple of 16.

int oldLength = array.size();
// resize array to array.size() + array.size() % 16.
...
// here fill up the new added elements with 0.
Array.fill(array, oldLength, array.size(), 0);

Cheers,
za-k/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
adrpoCommented:

You might be using null instead of zero.
And then you could display the null ones with a greyed collor (maybe).

Cheers,
za-k/
0
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.