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


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

where to use setAutoCreat

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

Show all headers | View raw


  To: comp.lang.java.gui
Hi, all,

I have a customized JTable and I use the Java 6.0 feature:
    table.setAutoCreateRowSorter(true)
to enable auto sorting on rows.

So when I add a new row to the table if the auto rowSorter is turned
on for a certain column (after I clicked on one column header to
enable the rowSorter), the new row will automatically jump to the
position according to the sorting result.

But I want the new row always at the end of the table when added. So I
want to turn off the auto sorting when adding a new row. I check the
java document and find the only possible method I can all on JTable,
or tableModel is
    table.setAutoCreateRowSorter(false);

I add the line in my table.addRow() method but it doesn't work, the
sorter still executes.
    public void addRow (MyObject rowData){
            this. setAutoCreateRowSorter(false);
            this.getModel.addRow(rowData);
}

 I wonder how can I achieve my goal. i.e. use the autoRowSorter given
by JTable but disable it when new row is added to my table untill next
time user click on a column to activate the sorter again.


BTW, The doc for the setAutoCreateRowSorter() method is:
/**
     * Specifies whether a {@code RowSorter} should be created for the
     * table whenever its model changes.
     * <p>
     * When {@code setAutoCreateRowSorter(true)} is invoked, a {@code
     * TableRowSorter} is immediately created and installed on the
     * table.  While the {@code autoCreateRowSorter} property remains
     * {@code true}, every time the model is changed, a new {@code
     * TableRowSorter} is created and set as the table's row sorter.
*/
It doesn't tell clearly about what happen or when should set it to
false.

---
 * 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 | NextNext 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