converting selected col index of jtable to its model's col index - Java

This is a discussion on converting selected col index of jtable to its model's col index - Java ; during sorting, the jTable row index no longer match to its model. hence, i will need to perform the following coversion. final int row = jTable1.getSelectedRow(); final int modelIndex = jTable1.getRowSorter().convertRowIndexToModel(row); however, for the col index, it will also no ...

+ Reply to Thread
Results 1 to 2 of 2

converting selected col index of jtable to its model's col index

  1. Default converting selected col index of jtable to its model's col index

    during sorting, the jTable row index no longer match to its model.
    hence, i will need to perform the following coversion.

    final int row = jTable1.getSelectedRow();
    final int modelIndex =
    jTable1.getRowSorter().convertRowIndexToModel(row);

    however, for the col index, it will also no longer match to its model
    col index, the user is dragging around the cols. so, how can i
    concerted the selected col index to model's?

    thank you.


  2. Default Re: converting selected col index of jtable to its model's col index

    On Apr 1, 7:31 am, yancheng.ch... wrote:
    > during sorting, the jTable row index no longer match to its model.
    > hence, i will need to perform the following coversion.
    >
    > final int row = jTable1.getSelectedRow();
    > final int modelIndex =
    > jTable1.getRowSorter().convertRowIndexToModel(row);
    >
    > however, for the col index, it will also no longer match to its model
    > col index, the user is dragging around the cols. so, how can i
    > concerted the selected col index to model's?
    >
    > thank you.


    Hi Yancheng,

    Try something like this, where columnIndex is your selected column
    index.

    TableColumn column = jTable1.getColumnModel().getColumn(columnIndex);
    int modelColumnIndex = column.getModelIndex();

    Cheers,
    Dan Andrews
    -------------------
    http://www.ansir.ca


+ Reply to Thread

Similar Threads

  1. index of selected radiobutton?
    By Application Development in forum CSharp
    Replies: 0
    Last Post: 12-06-2007, 04:53 AM
  2. Dropdown list selected index problem.
    By Application Development in forum CSharp
    Replies: 0
    Last Post: 11-09-2007, 12:48 PM
  3. ListView - Get the index of selected item
    By Application Development in forum CSharp
    Replies: 2
    Last Post: 08-15-2007, 10:39 AM
  4. JTable calls setValueAt with index out of bounds
    By Application Development in forum Java
    Replies: 2
    Last Post: 03-22-2007, 02:25 AM
  5. newbie: how to get radio button selected index and value
    By Application Development in forum Javascript
    Replies: 2
    Last Post: 11-14-2003, 04:29 AM