Results 1 to 3 of 3
  1. #1
    Alan is offline Member
    Join Date
    May 2007
    Posts
    39
    Rep Power
    0

    Default sort columns in jtable

    Hello people!
    I have the following question:

    I have a jtable with 3 columns.
    I want when I click in any column, the jtable sort its information by the column clicked.
    do you understand?
    please help me

  2. #2
    Freddie is offline Member
    Join Date
    May 2007
    Posts
    41
    Rep Power
    0

    Default

    hello
    please visit this url:


    https://jdnc.dev.java.net/ check that the second example use a jtable

    another way to do it is:

    Java Code:
    JTable table = new JTable() ;
    
    ... 
    JTableHeader header = table.getTableHeader() ;
    
    
    header.addMouseListener(
      new MouseAdapter()
      {
        void mouseClicked(MouseEvent e)
        {
          JTableHeader h = (JTableHeader)e.getSource() ;
          int nColumn = h.columnAtPoint(e.getPoint())
      
          if (nColumn != -1)
            sortColumn(nColumn, h.getTable().getModel()) ;
        }
    
        void sortColumn(int nColumn, TableModel model)
        {
         
    
         }
      }
    ) ;
    bye bye freddie

  3. #3
    Marty is offline Member
    Join Date
    May 2007
    Posts
    38
    Rep Power
    0

Similar Threads

  1. How to sort column in JTable
    By johnt in forum AWT / Swing
    Replies: 3
    Last Post: 06-14-2008, 05:48 AM
  2. How to sort a list using Bubble sort algorithm
    By Java Tip in forum Algorithms
    Replies: 3
    Last Post: 04-29-2008, 08:04 PM
  3. Using Columns With JTextField
    By The Evil Genius in forum AWT / Swing
    Replies: 1
    Last Post: 03-17-2008, 01:01 AM
  4. Getting names of table columns
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-07-2008, 08:39 AM
  5. Problems with JSF (columns)
    By Peter in forum JavaServer Faces (JSF)
    Replies: 2
    Last Post: 07-04-2007, 06:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •