get JTable Reverse Selected Rows - Java Swing

Java examples for Swing:JTable Row

Description

get JTable Reverse Selected Rows

Demo Code


//package com.java2s;

import java.util.Collection;
import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;
import javax.swing.JTable;

public class Main {
    public static Collection<Integer> getReverseSelectedRows(JTable table) {
        Set<Integer> rows = new TreeSet<Integer>(new Comparator<Integer>() {
            public int compare(Integer o1, Integer o2) {
                return o2.compareTo(o1);
            }//from  www  . j a  va2 s .c o  m
        });

        for (int r : table.getSelectedRows())
            rows.add(r);

        return rows;
    }
}

Related Tutorials