Add rows in a JTable in ascending order

1

I'm doing an RBC system to check for similarity between computers. I would like to sort my table rows by the probability value. The problem is that the table has around 9,500,000 rows. Does anyone know how to sort rows by column?

Here is the method I'm using in my code:

package mce;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.DefaultListModel;
import javax.swing.table.DefaultTableModel;

public class MCE {

public static double  retornaSimGabinete(String a1, String a2){
        if (a1.equals("Full Tower") && a2.equals("Full Tower"))  {
                return 1;
        } else if (a1.equals("Mid Tower") && a2.equals("Mid Tower")) {
                return 1;
        } else if ((a1.equals("Full Tower") && a2.equals("Mid Tower")) || (a2.equals("Full Tower") && a1.equals("Mid Tower"))) {
                return 0.5;
        } else {
            return 0;
        }
}

public static double retornaSimProc (String a1, String a2) {
        if (a1.equals("i7 6700K") && a2.equals("i7 6700K")) {
                return 1;
        } else if (a1.equals("i7 6700") && a2.equals("i7 6700")) {
                return 1;
        } else if (a1.equals("i5 6600K") && a2.equals("i5 6600K")) {
                return 1;
        } else if (a1.equals("i5 6600") && a2.equals("i5 6600")) {
                return 1;
        } else if ((a1.equals("i7 6700K") && a2.equals("i7 6700")) || (a2.equals("i7 6700K") && a1.equals("i7 6700"))) {
                return 0.8;
        } else if ((a1.equals("i7 6700K") && a2.equals("i5 6600K")) || (a2.equals("i7 6700K") && a1.equals("i5 6600K"))) {
                return 0.6;    
        } else if ((a1.equals("i7 6700K") && a2.equals("i5 6600")) || (a2.equals("i7 6700K") && a1.equals("i5 6600"))) {
                return 0.4;
        } else if ((a1.equals("i7 6700") && a2.equals("i5 6600K")) || (a2.equals("i7 6700") && a1.equals("i5 6600K"))) {
                return 0.5;
        } else if ((a1.equals("i7 6700") && a2.equals("i5 6600")) || (a2.equals("i7 6700") && a1.equals("i5 6600"))) {
                return 0.7;
        } else if ((a1.equals("i5 6600K") && a2.equals("i5 6600")) || (a2.equals("i5 6600K") && a1.equals("i5 6600"))) {
                return 0.8;
        } else {
                return 0;
        }
}   

public static double retornaSimMem (String a1, String a2) {
        if (a1.equals("HyperX 8GB 1600") && a2.equals("HyperX 8GB 1600")) {
                return 1;
        } else if (a1.equals("HyperX 8GB 1866") && a2.equals("HyperX 8GB 1866")) {
                return 1;
        } else if (a1.equals("HyperX 8GB 2133") && a2.equals("HyperX 8GB 2133")) {
                return 1;
        } else if (a1.equals("Vengeance 8GB 1600") && a2.equals("Vengeance 8GB 1600")) {
                return 1;
        } else if ((a1.equals("HyperX 8GB 1600") && a2.equals("HyperX 8GB 1866")) || (a2.equals("HyperX 8GB 1600") && a1.equals("HyperX 8GB 1866"))) {
                return 0.8;
        } else if ((a1.equals("HyperX 8GB 1600") && a2.equals("HyperX 8GB 2133")) || (a2.equals("HyperX 8GB 1600") && a1.equals("HyperX 8GB 2133"))) {
                return 0.5;    
        } else if ((a1.equals("HyperX 8GB 1600") && a2.equals("Vengeance 8GB 1600")) || (a2.equals("HyperX 8GB 1600") && a1.equals("Vengeance 8GB 1600"))) {
                return 0.9;
        } else if ((a1.equals("HyperX 8GB 1866") && a2.equals("HyperX 8GB 2133")) || (a2.equals("HyperX 8GB 1866") && a1.equals("HyperX 8GB 2133"))) {
                return 0.7;
        } else if ((a1.equals("HyperX 8GB 1866") && a2.equals("Vengeance 8GB 1600")) || (a2.equals("HyperX 8GB 1866") && a1.equals("Vengeance 8GB 1600"))) {
                return 0.8;
        } else if ((a1.equals("HyperX 8GB 2133") && a2.equals("Vengeance 8GB 1600")) || (a2.equals("HyperX 8GB 2133") && a1.equals("Vengeance 8GB 1600"))) {
                return 0.5;
        } else {
                return 0;
        }
}   

public static double retornaSimHd (String a1, String a2) {
        if (a1.equals("WD 1TB 7200") && a2.equals("WD 1TB 7200")) {
                return 1;
        } else if (a1.equals("Seagate 1TB 7200") && a2.equals("Seagate 1TB 7200")) {
                return 1;
        } else if (a1.equals("Seagate 2TB 7200") && a2.equals("Seagate 2TB 7200")) {
                return 1;
        } else if ((a1.equals("WD 1TB 7200") && a2.equals("Seagate 1TB 7200")) || (a2.equals("WD 1TB 7200") && a1.equals("Seagate 1TB 7200"))) {
                return 0.9;
        } else if ((a1.equals("WD 1TB 7200") && a2.equals("Seagate 2TB 7200")) || (a2.equals("WD 1TB 7200") && a1.equals("Seagate 2TB 7200"))) {
                return 0.7;    
        } else if ((a1.equals("Seagate 1TB 7200") && a2.equals("Seagate 2TB 7200")) || (a2.equals("Seagate 1TB 7200") && a1.equals("Seagate 2TB 7200"))) {
                return 0.7;
        } else {
                return 0;
        }
}

public static double retornaSimTeclado (String a1, String a2) {
        if (a1.equals("Razer BlackWidow") && a2.equals("Razer BlackWidow")) {
                return 1;
        } else if (a1.equals("Razer DeathStalker") && a2.equals("Razer DeathStalker")) {
                return 1;
        } else if (a1.equals("Razer Cynosa") && a2.equals("Razer Cynosa")) {
                return 1;
        } else if ((a1.equals("Razer BlackWidow") && a2.equals("Razer DeathStalker")) || (a2.equals("Razer BlackWidow") && a1.equals("Razer DeathStalker"))) {
                return 0.8;
        } else if ((a1.equals("Razer BlackWidow") && a2.equals("Razer Cynosa")) || (a2.equals("Razer BlackWidow") && a1.equals("Razer Cynosa"))) {
                return 0.6;    
        } else if ((a1.equals("Razer DeathStalker") && a2.equals("Razer Cynosa")) || (a2.equals("Razer DeathStalker") && a1.equals("Razer Cynosa"))) {
                return 0.7;
        } else {
                return 0;
        }
}

public static double  retornaSimRefrigeracao(String a1, String a2){
        if (a1.equals("Água") && a2.equals("Água"))  {
                return 1;
        } else if (a1.equals("Ar") && a2.equals("Ar")) {
                return 1;
        } else if ((a1.equals("Água") && a2.equals("Ar")) || (a2.equals("Água") && a1.equals("Ar"))) {
                return 0.5;
        } else {
            return 0;
        }
}

public static double retornaSimSsd (String a1, String a2) {
        if (a1.equals("Kingston 120GB") && a2.equals("Kingston 120GB")) {
                return 1;
        } else if (a1.equals("Sandisk 120GB") && a2.equals("Sandisk 120GB")) {
                return 1;
        } else if (a1.equals("Kingston 240GB") && a2.equals("Kingston 240GB")) {
                return 1;
        } else if (a1.equals("Sandisk 240GB") && a2.equals("Sandisk 240GB")) {
                return 1;
        } else if ((a1.equals("Kingston 120GB") && a2.equals("Sandisk 120GB")) || (a2.equals("Kingston 120GB") && a1.equals("Sandisk 120GB"))) {
                return 0.9;
        } else if ((a1.equals("Kingston 120GB") && a2.equals("Kingston 240GB")) || (a2.equals("Kingston 120GB") && a1.equals("Kingston 240GB"))) {
                return 0.7;    
        } else if ((a1.equals("Kingston 120GB") && a2.equals("Sandisk 240GB")) || (a2.equals("Kingston 120GB") && a1.equals("Sandisk 240GB"))) {
                return 0.6;
        } else if ((a1.equals("Sandisk 120GB") && a2.equals("Kingston 240GB")) || (a2.equals("Sandisk 120GB") && a1.equals("Kingston 240GB"))) {
                return 0.6;
        } else if ((a1.equals("Sandisk 120GB") && a2.equals("Sandisk 240GB")) || (a2.equals("Sandisk 120GB") && a1.equals("Sandisk 240GB"))) {
                return 0.7;
        } else if ((a1.equals("Kingston 240GB") && a2.equals("Sandisk 240GB")) || (a2.equals("Kingston 240GB") && a1.equals("Sandisk 240GB"))) {
                return 0.9;
        } else {
                return 0;
        }
}   

public static double retornaSimGpu(String a1, String a2) {
        if (a1.equals("AMD R9 390") && a2.equals("AMD R9 390")) {
                return 1;
        } else if (a1.equals("AMD R9 Fury") && a2.equals("AMD R9 Fury")) {
                return 1;
        } else if (a1.equals("AMD R9 390X") && a2.equals("AMD R9 390X")) {
                return 1;
        } else if (a1.equals("GTX 980 TI") && a2.equals("GTX 980 TI")) {
                return 1;
        } else if ((a1.equals("AMD R9 390") && a2.equals("AMD R9 Fury")) || (a2.equals("AMD R9 390") && a1.equals("AMD R9 Fury"))) {
                return 0.8;
        } else if ((a1.equals("AMD R9 390") && a2.equals("AMD R9 390X")) || (a2.equals("AMD R9 390") && a1.equals("AMD R9 390X"))) {
                return 0.7;    
        } else if ((a1.equals("AMD R9 390") && a2.equals("GTX 980 TI")) || (a2.equals("AMD R9 390") && a1.equals("GTX 980 TI"))) {
                return 0.6;
        } else if ((a1.equals("AMD R9 Fury") && a2.equals("AMD R9 390X")) || (a2.equals("AMD R9 Fury") && a1.equals("AMD R9 390X"))) {
                return 0.7;
        } else if ((a1.equals("AMD R9 Fury") && a2.equals("GTX 980 TI")) || (a2.equals("AMD R9 Fury") && a1.equals("GTX 980 TI"))) {
                return 0.6;
        } else if ((a1.equals("AMD R9 390X") && a2.equals("GTX 980 TI")) || (a2.equals("AMD R9 390X") && a1.equals("GTX 980 TI"))) {
                return 0.8;
        } else {
                return 0;
        }
} 

public static double retornaSimMouse (String a1, String a2) {
        if (a1.equals("Razer Naga") && a2.equals("Razer Naga")) {
                return 1;
        } else if (a1.equals("Razer Abyssus") && a2.equals("Razer Abyssus")) {
                return 1;
        } else if (a1.equals("Razer Krait") && a2.equals("Razer Krait")) {
                return 1;
        } else if (a1.equals("Razer Deathadder") && a2.equals("Razer Deathadder")) {
                return 1;
        } else if ((a1.equals("Razer Naga") && a2.equals("Razer Abyssus")) || (a2.equals("Razer Naga") && a1.equals("Razer Abyssus"))) {
                return 0.7;
        } else if ((a1.equals("Razer Naga") && a2.equals("Razer Krait")) || (a2.equals("Razer Naga") && a1.equals("Razer Krait"))) {
                return 0.5;    
        } else if ((a1.equals("Razer Naga") && a2.equals("Razer Deathadder")) || (a2.equals("Razer Naga") && a1.equals("Razer Deathadder"))) {
                return 0.3;
        } else if ((a1.equals("Razer Abyssus") && a2.equals("Razer Krait")) || (a2.equals("Razer Abyssus") && a1.equals("Razer Krait"))) {
                return 0.6;
        } else if ((a1.equals("Razer Abyssus") && a2.equals("Razer Deathadder")) || (a2.equals("Razer Abyssus") && a1.equals("Razer Deathadder"))) {
                return 0.7;
        } else if ((a1.equals("Razer Deathadder") && a2.equals("Razer Krait")) || (a2.equals("Razer Deathadder") && a1.equals("Razer Krait"))) {
                return 0.8;
        } else {
                return 0;
        }
}   

public static double retornaSimFonte (String a1, String a2) {
        if (a1.equals("EVGA 1600W") && a2.equals("EVGA 1600W")) {
                return 1;
        } else if (a1.equals("Corsair 1500W") && a2.equals("Corsair 1500W")) {
                return 1;
        } else if (a1.equals("Coolermaster 1200W") && a2.equals("Coolermaster 1200W")) {
                return 1;
        } else if (a1.equals("Seasonic 1000W") && a2.equals("Seasonic 1000W")) {
                return 1;
        } else if ((a1.equals("EVGA 1600W") && a2.equals("Corsair 1500W")) || (a2.equals("EVGA 1500W") && a1.equals("Corsair 1500W"))) {
                return 0.8;
        } else if ((a1.equals("EVGA 1600W") && a2.equals("Coolermaster 1200W")) || (a2.equals("EVGA 1600W") && a1.equals("Coolermaster 1200W"))) {
                return 0.6;    
        } else if ((a1.equals("EVGA 1600W") && a2.equals("Seasonic 1000W")) || (a2.equals("EVGA 1600W") && a1.equals("Seasonic 1000W"))) {
                return 0.4;
        } else if ((a1.equals("Corsair 1500W") && a2.equals("Coolermaster 1200W")) || (a2.equals("Corsair 1500W") && a1.equals("Coolermaster 1200W"))) {
                return 0.7;
        } else if ((a1.equals("Corsair 1500W") && a2.equals("Seasonic 1000W")) || (a2.equals("Corsair 1500W") && a1.equals("Seasonic 1000W"))) {
                return 0.5;
        } else if ((a1.equals("Coolermaster 1200W") && a2.equals("Seasonic 1000W")) || (a2.equals("Coolermaster 1200W") && a1.equals("Seasonic 1000W"))) {
                return 0.8;
        } else {
                return 0;
        }
}

public static double retornaSimMonitor (String a1, String a2) {
        if (a1.equals("Benq 27p 144Hz") && a2.equals("Benq 27p 144Hz")) {
                return 1;
        } else if (a1.equals("Asus 27p 144Hz") && a2.equals("Asus 27p 144Hz")) {
                return 1;
        } else if (a1.equals("Asus 27p QuadHD") && a2.equals("Asus 27p QuadHD")) {
                return 1;
        } else if (a1.equals("LG 25p FullHD") && a2.equals("LG 25p FullHD")) {
                return 1;
        } else if ((a1.equals("Benq 27p 144Hz") && a2.equals("Asus 27p 144Hz")) || (a2.equals("Benq 27p 144Hz") && a1.equals("Asus 27p 144Hz"))) {
                return 0.8;
        } else if ((a1.equals("Benq 27p 144Hz") && a2.equals("Asus 27p QuadHD")) || (a2.equals("Benq 27p 144Hz") && a1.equals("Asus 27p QuadHD"))) {
                return 0.6;    
        } else if ((a1.equals("Benq 27p 144Hz") && a2.equals("LG 25p FullHD")) || (a2.equals("Benq 27p 144Hz") && a1.equals("LG 25p FullHD"))) {
                return 0.4;
        } else if ((a1.equals("Asus 27p 144Hz") && a2.equals("Asus 27p QuadHD")) || (a2.equals("Asus 27p 144Hz") && a1.equals("Asus 27p QuadHD"))) {
                return 0.7;
        } else if ((a1.equals("Asus 27p 144Hz") && a2.equals("LG 25p FullHD")) || (a2.equals("Asus 27p 144Hz") && a1.equals("LG 25p FullHD"))) {
                return 0.5;
        } else if ((a1.equals("Asus 27p QuadHD") && a2.equals("LG 25p FullHD")) || (a2.equals("Asus 27p QuadHD") && a1.equals("LG 25p FullHD"))) {
                return 0.8;
        } else {
                return 0;
        }
}

public static double retornaSimHeadset (String a1, String a2) {
        if (a1.equals("Razer Kraken") && a2.equals("Razer Kraken")) {
                return 1;
        } else if (a1.equals("Razer TiaMat") && a2.equals("Razer TiaMat")) {
                return 1;
        } else if (a1.equals("Razer Chiamera") && a2.equals("Razer Chiamera")) {
                return 1;
        } else if (a1.equals("Razer Manowar") && a2.equals("Razer Manowar")) {
                return 1;
        } else if ((a1.equals("Razer Kraken") && a2.equals("Razer TiaMat")) || (a2.equals("Razer Kraken") && a1.equals("Razer TiaMat"))) {
                return 0.7;
        } else if ((a1.equals("Razer Kraken") && a2.equals("Razer Chiamera")) || (a2.equals("Razer Kraken") && a1.equals("Razer Chiamera"))) {
                return 0.6;    
        } else if ((a1.equals("Razer Kraken") && a2.equals("Razer Manowar")) || (a2.equals("Razer Kraken") && a1.equals("Razer Manowar"))) {
                return 0.5;
        } else if ((a1.equals("Razer TiaMat") && a2.equals("Razer Chiamera")) || (a2.equals("Razer TiaMat") && a1.equals("Razer Chiamera"))) {
                return 0.7;
        } else if ((a1.equals("Razer TiaMat") && a2.equals("Razer Manowar")) || (a2.equals("Razer TiaMat") && a1.equals("Razer Manowar"))) {
                return 0.5;
        } else if ((a1.equals("Razer Chiamera") && a2.equals("Razer Manowar")) || (a2.equals("Razer Chiamera") && a1.equals("Razer Manowar"))) {
                return 0.8;
        } else {
                return 0;
        }
}

public static double retornaSimMotherboard (String a1, String a2) {
        if (a1.equals("ATX Maximus VIII") && a2.equals("ATX Maximus VIII")) {
                return 1;
        } else if (a1.equals("ATX ROG STRIX") && a2.equals("ATX ROG STRIX")) {
                return 1;
        } else if (a1.equals("ATX Sabertooth") && a2.equals("ATX Sabertooth")) {
                return 1;
        } else if (a1.equals("ATX 970 PRO") && a2.equals("ATX 970 PRO")) {
                return 1;
        } else if ((a1.equals("ATX Maximus VIII") && a2.equals("ATX ROG STRIX")) || (a2.equals("ATX Maximus VIII") && a1.equals("ATX ROG STRIX"))) {
                return 0.8;
        } else if ((a1.equals("ATX Maximus VIII") && a2.equals("ATX Sabertooth")) || (a2.equals("ATX Maximus VIII") && a1.equals("ATX Sabertooth"))) {
                return 0.6;    
        } else if ((a1.equals("ATX Maximus VIII") && a2.equals("ATX 970 PRO")) || (a2.equals("ATX Maximus VIII") && a1.equals("ATX 970 PRO"))) {
                return 0.5;
        } else if ((a1.equals("ATX ROG STRIX") && a2.equals("ATX Sabertooth")) || (a2.equals("ATX ROG STRIX") && a1.equals("ATX Sabertooth"))) {
                return 0.7;
        } else if ((a1.equals("ATX ROG STRIX") && a2.equals("ATX 970 PRO")) || (a2.equals("ATX ROG STRIX") && a1.equals("ATX 970 PRO"))) {
                return 0.6;
        } else if ((a1.equals("ATX Sabertooth") && a2.equals("ATX 970 PRO")) || (a2.equals("ATX Sabertooth") && a1.equals("ATX 970 PRO"))) {
                return 0.9;
        } else {
                return 0;
        }
}
    public static void main(String[] args) {

        ArrayList<String> gabinete = new ArrayList<String>();
        ArrayList<String> processador = new ArrayList<String>();
        ArrayList<String> memoria = new ArrayList<String>();
        ArrayList<String> hd = new ArrayList<String>();
        ArrayList<String> ssd = new ArrayList<String>();
        ArrayList<String> gpu = new ArrayList<String>();
        ArrayList<String> teclado = new ArrayList<String>();
        ArrayList<String> mouse = new ArrayList<String>();
        ArrayList<String> fonte = new ArrayList<String>();
        ArrayList<String> refrigeracao = new ArrayList<String>();
        ArrayList<String> monitor = new ArrayList<String>();
        ArrayList<String> headset = new ArrayList<String>();
        ArrayList<String> motherboard = new ArrayList<String>();

         gabinete.add("Mid Tower");
        gabinete.add("Full Tower");
        processador.add("i7 6700K");
        processador.add("i7 6700");
        processador.add("i5 6600K");
        processador.add("i5 6600");
        memoria.add("HyperX 8GB 1600");
        memoria.add("Vengeance 8GB 1600");
        memoria.add("HyperX 8GB 1866");
        memoria.add("HyperX 8GB 2133");
        hd.add("WD 1TB 7200");
        hd.add("Seagate 1TB 7200");
        hd.add("Seagate 2TB 7200");
        ssd.add("Kingston 120GB");
        ssd.add("Sandisk 120GB");
        ssd.add("Kingston 240GB");
        ssd.add("Sandisk 240GB");
        gpu.add("AMD R9 390");
        gpu.add("AMD R9 Fury");
        gpu.add("AMD R9 390X");
        gpu.add("GTX 980 TI");
        teclado.add("Razer BlackWidow");
        teclado.add("Razer DeathStalker");
        teclado.add("Razer Cynosa");
        mouse.add("Razer Naga");
        mouse.add("Razer Abyssus");
        mouse.add("Razer Krait");
        mouse.add("Razer Deathadder");
        fonte.add("EVGA 1600W");
        fonte.add("Corsair 1500W");
        fonte.add("Coolermaster 1200W");
        fonte.add("SeaSonic 1000W");
        refrigeracao.add("Água");
        refrigeracao.add("Ar");
        monitor.add("Benq 27p 144Hz");
        monitor.add("Asus 27p 144Hz");
        monitor.add("Asus 27p QuadHD");
        monitor.add("LG 25p FullHD");
        headset.add("Razer Kraken");
        headset.add("Razer TiaMat");
        headset.add("Razer Chiamera");
        headset.add("Razer Manowar");
        motherboard.add("ATX Maximus VIII");
        motherboard.add("ATX ROG STRIX");
        motherboard.add("ATX Sabertooth");
        motherboard.add("ATX 970 PRO");

         String gabinetesel;
        String processadorsel;
        String memoriasel;
        String hdsel;
        String ssdsel;
        String gpusel;
        String tecladosel;
        String mousesel;
        String fontesel;
        String refrigeracaosel;
        String monitorsel;
        String headsetsel;
        String motherboardsel;
        // VARIAVEIS PARA RECEBER O PESO DE CADA VARIAVEL DO RBC
        Double pesogabinete;
        Double pesoprocessador;
        Double pesomemoria;
        Double pesohd;
        Double pesossd;
        Double pesogpu;
        Double pesoteclado;
        Double pesomouse;
        Double pesofonte;
        Double pesorefrigeracao;
        Double pesomonitor;
        Double pesoheadset;
        Double pesomotherboard;
        // PEGA O VALOR SELECIONADO DA LISTA E COLOCA NA VARIAVEL CRIADA PARA ISSO
        gabinetesel = "Mid Tower";
        processadorsel = "i7 6700K";
        memoriasel = "HyperX 8GB 1600";
        hdsel = "WD 1TB 7200";
        ssdsel = "Kingston 120GB";
        gpusel = "AMD R9 390";
        tecladosel = "Razer BlackWidow";
        mousesel = "Razer Naga";
        fontesel = "EVGA 1600W";
        refrigeracaosel = "Água";
        monitorsel = "Benq 27p 144Hz";
        headsetsel = "Razer Kraken";
        motherboardsel = "ATX Maximus VIII";
        // PEGA OS VALORES DE PESO DE CADA VARIAVEL     
        pesogabinete = 1.0;
        pesoprocessador = 1.0;
        pesomemoria = 1.0;
        pesohd = 1.0;
        pesossd = 1.0;
        pesogpu = 1.0;
        pesoteclado = 1.0;
        pesomouse = 1.0;
        pesofonte = 1.0;
        pesorefrigeracao = 1.0;
        pesomonitor = 1.0;
        pesoheadset = 1.0;
        pesomotherboard = 1.0;

        Vector row = new Vector();
        //cria tabela
        DefaultTableModel model = (DefaultTableModel) jTable1.getModel();

        double prob;
        for (int i = 0; i < 2; i ++) {
            for (int j = 0; j < 4; j++){
                for (int k = 0; k < 4; k++){
                    for (int l = 0; l < 3; l++){
                        for (int m = 0; m < 4; m++){
                            for (int n = 0; n < 4; n++){
                                for (int o = 0; o < 3; o++){
                                    for (int p = 0; p < 4; p++){
                                        for (int q = 0; q < 4; q++) {
                                            for (int r = 0; r < 2; r++){
                                                for (int s = 0; s < 4; s++){
                                                    for (int t = 0; t < 4; t++){
                                                        for (int u = 0; u < 4; u++) {
                                                             prob = ((pesogabinete * retornaSimGabinete(gabinetesel,gabinete.get(i))) + (pesoprocessador *(retornaSimProc(processadorsel,processador.get(j)))) + (pesomemoria * (retornaSimMem(memoriasel,memoria.get(k)))) + (pesohd * (retornaSimHd(hdsel,hd.get(l)))) + (pesossd * (retornaSimSsd(ssdsel,ssd.get(m)))) + (pesogpu * (retornaSimGpu(gpusel,gpu.get(n)))) +  (pesoteclado * (retornaSimTeclado(tecladosel,teclado.get(o)))) + (pesomouse * (retornaSimMouse(mousesel,mouse.get(p)))) + (pesofonte * (retornaSimFonte(fontesel,fonte.get(q)))) + (pesorefrigeracao * (retornaSimRefrigeracao(refrigeracaosel,refrigeracao.get(r)))) + (pesomonitor * (retornaSimMonitor(monitorsel,monitor.get(s)))) + (pesoheadset * (retornaSimHeadset(headsetsel,headset.get(t)))) + (pesomotherboard * (retornaSimMotherboard(motherboardsel,motherboard.get(u))))) / (pesogabinete+pesoprocessador+pesomemoria+pesohd+pesossd+pesomouse+pesoteclado+pesogpu+pesofonte+pesorefrigeracao+pesomonitor+pesoheadset+pesomotherboard);
                                                             System.out.println(gabinete.get(i) + "," + processador.get(j) + "," + memoria.get(k) + "," + hd.get(l) + "," + ssd.get(m) + "," + gpu.get(n) + "," + teclado.get(o) + "," + mouse.get(p) + "," + fonte.get(q) + "," + refrigeracao.get(r) + "," + monitor.get(s) + "," + headset.get(t) + "," + motherboard.get(u) + " --> " + (prob*100) + "%" );
 row.add(gabinete.get(i));
                                                             row.add(processador.get(j));
                                                             row.add(memoria.get(k));
                                                             row.add(hd.get(l));
                                                             row.add(ssd.get(m));
                                                             row.add(gpu.get(n));
                                                             row.add(teclado.get(o));
                                                             row.add(mouse.get(p));
                                                             row.add(fonte.get(q));
                                                             row.add(refrigeracao.get(r));
                                                             row.add(monitor.get(s));
                                                             row.add(headset.get(t));
                                                             row.add(motherboard.get(u));
                                                             row.add(Double.toString(prob));
                                                             model.addRow (row);

                                                        }                                  
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                            }
                        }
                    }
                }
            }
        }
    }         


















    }
    
asked by anonymous 24.09.2016 / 18:07

1 answer

1

To reorder according to the data in a particular column, you must first implement the getColumnClass of your TableModel , so that the data type of the column you want to sort is known, over there.

You also need to set RowSorter for your table , since it is this class that allows to define a filter and ordering in JTable . Once applied to JTable through setRowSorter , just call toggleSortOrder passing the column as a parameter.

See an example of using RowSorter and toggleSortOrder :

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;

public class RowSorterDemo {

    public void createAndShowGUI() {
        JFrame frame = new JFrame("Sort Table Demo");

        Object rows[][] = {
            {"J", 23},
            {"R", 24,},
            {"E", 21,},
            {"B", 27,},
            {"A", 25,},
            {"S", 22,}};

        String columns[] = {"Name", "Age"};

        TableModel model = new DefaultTableModel(rows, columns) {
            @Override
            public Class getColumnClass(int column) {
                switch (column) {
                    case 0:
                        return String.class;
                    case 1:
                        return Integer.class;
                    default:
                        return Object.class;
                }
            }
        };

        JTable table = new JTable(model);
        //é o RowSorter que ordenará sua tabela
        RowSorter<TableModel> sorter = new TableRowSorter<>(model);
        //aplica o sorter a tabela
        table.setRowSorter(sorter);

        JScrollPane pane = new JScrollPane(table);

        JButton button = new JButton("OrdenarPorIdade");
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //passa o rowsorter e a coluna da tabela
                //neste caso é a segunda
                reorderingTableByColumn(sorter, 1);
            }
        });

        frame.add(pane, BorderLayout.CENTER);
        frame.add(button, BorderLayout.SOUTH);
        frame.setPreferredSize(new Dimension(300, 200));
        frame.pack();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }

    private void reorderingTableByColumn(RowSorter sorter, int column) {
        //reordena a tabela pela coluna Age
        sorter.toggleSortOrder(column);
    }

    public static void main(String args[]) {
        EventQueue.invokeLater(new RowSorterDemo().createAndShowGUI());
    }
}

The result of the example is:

Intheexample,Icreatedamethodtopartthatreordersthetablebythesecondcolumnattheclickofabutton,butyoucanleavethecallrightatstartup.

  

Note:Itisworthmentioningthat,becauseofthenumberofdatayouhaveinthistable,thissolutionmaycausesmallcrashesintheapplicationeverytimeyoureorganizethetable.

References:

Using RowSorter to sort a JTable

Sorting and Filtering

Sorting and Filtering Tables

Table Sorting and Filtering

    
24.09.2016 / 21:36