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?
 
adrpoConnect With a Mentor Commented:

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
 
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
All Courses

From novice to tech pro — start learning today.