Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java: How to sort a JTable

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:

  • python print list to file
  • tkinter catch key
  • python iterate dict
  • python check if element in tuple
  • python python dom delete subentry
  • python catch keys
  • java class UsbHub
  • Check key existance Python dictionary
  • math modules python pi
  • copy arraylist to another arraylist java without collections

No comments yet.

Leave a Comment