Moving a Column in a JTable Component

Moving a column requires the index of the column to be moved and a position specified. The index of a column is 0-based; the first column has index 0. Positions are locations between columns. For example, if there are 2 columns in a table, there are 3 possible position – – 0, 1,and 2. Moving a column to position 0 makes the column the first column. Moving a column to position 2 makes the column the last column.
int rows = 10; int cols = 5; JTable table = new JTable(rows, cols); // Move the last visible column so it becomes the first visible column int vSrcColIndex = table.getColumnCount()-1; int vDstColIndex = 0; table.moveColumn(vSrcColIndex, vDstColIndex);

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.