Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #2258

Re: where to use setAutoC

From "Ray Ma" <ray.ma@THRWHITE.remove-dii-this>
Subject Re: where to use setAutoC
Message-ID <1187224253.457074.20520@e9g2000prf.googlegroups.com> (permalink)
Newsgroups comp.lang.java.gui
References <1187206548.935996.282280@q4g2000prc.googlegroups.com>
Date 2011-04-27 15:38 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui
I have a walk around that can disable the RowSorter. I find one tricky
thing is that even if you call:
      table.getRowSorter().setSortable(columnIndex,false);
if you have called:
      setSortable(columnIndex,true);
previously, it's actually still using the last sorting rule that you
apply to your table column, when the column sortable set to true.
e.g. If you have a quantity field and you click once: sort in
ascending order; twice: sort in descending order; then you call
setSortable(colIndex,false) and you add a new row, you'll find you can
no longer click on the table header to sort a column, BUT if you add a
new row, it is still added using descending order.

The right way is to use: table.setRowSorter(null) when you want to
disable column sorting.

The following code can achieve:
3 clicks on table header,1st: sort ascendingly, 2nd sort descendingly,
3rd disable sorter

class MyTable extends JTable{

 int headerClickCount =0;
 private TableRowSorter<XXTableModel> sorter =null;

 MyTable(TableModel tableModel){
    super(tableModel);
    ......
    sorter = new TableRowSorter(this.getTableModel());

 }
/**add mouse listener for mouse clicking on table header*/
public void addMouseListenerForHeader(){
        this.getTableHeader().addMouseListener(new MouseAdapter(){
            public void mousePressed(MouseEvent e){
                    headerClickCount++;
                    if(headerClickCount==3){
                        MyTable.this.setRowSorter(null);
                        headerClickCount=0;
                    }
                    else{
                        if(MyTable.this.getRowSorter()==null)
                            sorter.setModel(MyTable.this.tableModel);//
Must reset tableModel to the sorter
                        MyTable.this.setRowSorter(sorter);
                    }
                }
              });
 }

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

where to use setAutoCreat "Ray Ma" <ray.ma@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000
  Re: where to use setAutoC "Ray Ma" <ray.ma@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000

csiph-web