I have problems with the DefaultTableModel class in java

0

My problem consists of the following: I have a JFrame, which contains a JTable with several fields, among these, there is one called Payment whose characteristic is to inform the user if a client within the list paid or not. In an area of the UI I have a button called Sort whose function is to sort the list so that those with a brand (Already paid) go to the last the table, leaving in the upper part those who have not yet done so. Then, when I give the button 1 time, it places the first customer who paid in the position that corresponds to it and the others who also paid leave them in their position unless they touch said button n times and then it will be that it will order them correctly. Therefore, I do not understand if it is a problem of the DefaultTableModel class or if it is my algorithm. Then I leave the picture of the table in the UI and my method. Thanks in advance and good morning to all.

    /**
 * Ordena la lista de forma tal que agrupa a los clientes deudores 
 * a las primeras posiciones de la lista. Este método busca donde comienza
 * una consecución de clientes que ya hayan pagado y donde termina dependiedo 
 * de esto los coloca al final de la lista
 */
private void reorderList(){
    ArrayList<Integer> s_g = new ArrayList<>();
    boolean first = true;
    int i = 0, k = -1;
    while(i < dft.getRowCount()){
        //Asigna la posición en caso de ser el primero de la consecución a k
        if(first)
            first = (k = (boolean)dft.getValueAt(i, 1) ? i : -1) == -1;
        if(k != -1 && !(boolean)dft.getValueAt(i, 1)){
            first = true;
            //Calcula la cantidad de espacio ocupada por la consecución
            int busy = i-k;
            int pos = dft.getRowCount()-busy;
            //Guarda la posición de inicio de una consecución
            s_g.add(k);
            //Guarda la meta
            s_g.add(i);
            //Y el espacio a dejar al final de la fila en la tabla
            s_g.add(pos);           
        }
        i++;
    }
    i = 0;
    while(!s_g.isEmpty())
        dft.moveRow(s_g.remove(i), s_g.remove(i)-1, s_g.remove(i));
        i+=3;
}
    
asked by MarzoGomez 20.02.2018 в 07:20
source

0 answers