0

I would like to create a JTable with 2 items in the first row, 1 item in the second row, 2 items in the third row, 1 item in the fourth row, and so on. In addition, the first item in the rows with two items are aligned left and the second item in the rows with two items are aligned right. The item in the rows with one item is aligned left. So the first four rows look something like:

----------------------------
| item 1             item 2 |

| iteeeeem 3 //end of item 3|

| item 4            item 5 |

| iteeeeeeeeeeeeeeeeeeeem 6 |
_____________________________,

or the table looks like this enter image description here

So far, my code is

model = new DefaultTableModel();
model.addColumn("");
model.addColumn("");
model.addColumn("");
for (int i = 0; i < number_of_rows; i++){
model.addRow(new Object[] { ITEM_1, ITEM_2, ITEM_3 });}

This adds three items into the same row. How can I tweak the code to get what I need?

Thanks!

4

0 回答 0