Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #2258
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!86597e80!not-for-mail |
|---|---|
| From | "Ray Ma" <ray.ma@THRWHITE.remove-dii-this> |
| Subject | Re: where to use setAutoC |
| Message-ID | <1187224253.457074.20520@e9g2000prf.googlegroups.com> (permalink) |
| X-Comment-To | comp.lang.java.gui |
| Newsgroups | comp.lang.java.gui |
| In-Reply-To | <1187206548.935996.282280@q4g2000prc.googlegroups.com> |
| References | <1187206548.935996.282280@q4g2000prc.googlegroups.com> |
| Content-Type | text/plain; charset=IBM437 |
| Content-Transfer-Encoding | 8bit |
| X-Gateway | time.synchro.net [Synchronet 3.15a-Win32 NewsLink 1.92] |
| Lines | 55 |
| Date | Wed, 27 Apr 2011 15:38:04 GMT |
| NNTP-Posting-Host | 96.60.20.240 |
| X-Complaints-To | news@tds.net |
| X-Trace | newsreading01.news.tds.net 1303918684 96.60.20.240 (Wed, 27 Apr 2011 10:38:04 CDT) |
| NNTP-Posting-Date | Wed, 27 Apr 2011 10:38:04 CDT |
| Organization | TDS.net |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.gui:2258 |
Show key headers only | 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 | Next — Previous in thread | Find similar | Unroll 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