Java: How to sort a JTable

{filelink=901}
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
public class JTableSort{
public static void main(String[] args)
{
String nomColonne[] = { "Mois", "Valeur" };
Object[][] valeur = { { "Janvier", 0 }, { "Mares", 2 }, { "Ocrobre", 9 }, { "Decembre", 11 } };
TableModel model = new DefaultTableModel(valeur, nomColonne) {
public Class getColumnClass(int column) {
return getValueAt(0, column).getClass();
}
};
JTable table = new JTable(model);
TableRowSorter sorter = new TableRowSorter(model);
table.setRowSorter(sorter);
JScrollPane scrollPane = new JScrollPane(table);
JFrame frame = new JFrame("Sorting JTable");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(scrollPane);
frame.setSize(300, 200);
frame.setVisible(true);
}
} |
Users who found this page were searching for:
- calculating percentages in python
- python iterate dict
- copy arraylist to another arraylist java without collections
- java class UsbHub
- tkinter catch key
- math modules python pi
- Matcher group count
- Check key existance Python dictionary
- python catch keys
- python check if element in tuple