1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

sorting JTable

Discussion in 'All Other Software' started by mansi_3001, Jul 17, 2007.

Thread Status:
Not open for further replies.
  1. mansi_3001

    mansi_3001 Thread Starter

    Joined:
    Jul 17, 2007
    Messages:
    1
    public class MyTableApp extends JFrame {
    JTable myTable;
    JButton update;
    JButton insert;
    JButton delete;
    JPanel p,mainPanel;
    MyTabModel tm;
    DefaultTableModel tabModel;
    JScrollPane myPane;
    Vector rows,columns;
    protected JLabel titleLabel=new JLabel("Click table header to sort the column");

    //constructor
    MyTableApp(/*Connection con,String tableName*/){
    try{
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    }
    catch(Exception e){
    System.out.println("Error on look and feel");
    }

    tm = new MyTabModel(/*con,tableName*/);
    //TableSorterDemo ts=new TableSorterDemo();
    myTable = new JTable(tm);

    /*MyTabModel myModel = new MyTabModel();*/
    TableSorter sorter = new TableSorter(tm);
    sorter.addMouseListenerToHeaderInTable(myTable);

    myTable.setModel(tm);


    update = new JButton("Update/Save");
    insert = new JButton("Add");
    delete = new JButton("Delete(one at a time)");
    p = new JPanel();

    p.add(insert);
    p.add(delete);
    p.add(update);
    myPane = new JScrollPane(myTable,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    // myTable.setSelectionForeground(Color.white);
    // myTable.setSelectionBackground(Color.red);
    //myTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    //getContentPane().add(myPane);
    JTableHeader header = myTable.getTableHeader();
    header.setUpdateTableInRealTime(true);
    //header.addMouseListener(tm.new MouseListener());
    header.setReorderingAllowed(true);




    mainPanel=new JPanel();
    this.setSize(800,600);
    this.setExtendedState(JFrame.MAXIMIZED_BOTH);
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add("Center",myPane);
    mainPanel.add("South",p);
    mainPanel.setBackground(Color.white);
    p.setBackground(Color.white);
    myTable.getParent().setBackground(Color.white);
    this.getContentPane().add(mainPanel);
    this.setVisible(true);

    I am using class MyTableApp to create Jtable whereas the data is being populated from database using another class MyTabModel.i want to sort the columns in the JTable hence using TableSorter and TableMap from examples by sun.Now the problem is that instead of including the mouselistener in MyTableApp class above im nt able to sort the JTable.please help...its urgent..
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/596837

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice