The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing.table  [62 examples] > Columns  [11 examples]

e923. 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);

 Related Examples
e915. Converting a Column Index Between the View and Model in a JTable Component
e916. Enumerating the Columns in a JTable Component
e917. Setting the Width of a Column in a JTable Component
e918. Setting the Column Resize Mode of a JTable Component
e919. Locking the Width of a Column in a JTable Component
e920. Appending a Column to a JTable Component
e921. Inserting a Column in a JTable Component
e922. Removing a Column from a JTable Component
e924. Allowing the User to Move a Column in a JTable Component
e925. Allowing the User to Resize a Column in a JTable Component

See also: Cells    Column Heads    Editing    Events    Layout    Rows    Scrolling    Selection    Sorting    Table Model    Tool Tips   


© 2002 Addison-Wesley.