Swing/TablePagination のバックアップソース(No.2)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- バックアップ を表示
- Swing/TablePagination へ行く。
- 1 (2007-11-05 (月) 14:35:32)
- 2 (2008-03-26 (水) 20:28:31)
- 3 (2008-03-27 (木) 02:15:38)
- 4 (2008-03-30 (日) 01:38:27)
- 5 (2008-09-07 (日) 00:05:08)
- 6 (2008-11-03 (月) 21:51:54)
- 7 (2010-10-28 (木) 17:52:38)
- 8 (2011-08-15 (月) 15:51:42)
- 9 (2013-11-01 (金) 16:08:20)
- 10 (2013-11-01 (金) 21:21:16)
- 11 (2013-11-04 (月) 06:46:11)
- 12 (2014-03-18 (火) 19:04:02)
- 13 (2014-10-07 (火) 17:49:31)
- 14 (2014-11-08 (土) 01:41:12)
- 15 (2014-11-21 (金) 18:32:13)
- 16 (2015-12-26 (土) 15:57:47)
- 17 (2016-09-29 (木) 17:13:31)
- 18 (2017-10-27 (金) 16:26:13)
- 19 (2017-11-08 (水) 13:54:55)
- 20 (2018-02-24 (土) 19:51:30)
- 21 (2019-05-24 (金) 18:24:50)
- 22 (2021-02-17 (水) 08:21:11)
TITLE:RowFilterでJTableのページ分割 #navi(../) *RowFilterでJTableのページ分割 [#sff7ad1c] >編集者:[[Terai Atsuhiro>terai]]~ 作成日:2007-11-05~ 更新日:&lastmod; #contents **概要 [#p2b85520] JDK 6 で導入されたRowFilterを使って、JTableの行をPagination風に分割して表示します。 #screenshot **サンプルコード [#l576bdcf] #code{{ void initLinkBox(Box box, TestModel m, final TableRowSorter<TestModel> sorter, final int size, final int step) { m.setRowCount(0); for(int i=0;i<size;i++) { m.addTest(new Test("Name"+i, (i%2==0)?"":"comment...")); } box.removeAll(); final ButtonGroup bg = new ButtonGroup(); box.add(Box.createHorizontalGlue()); box.setBorder(BorderFactory.createEmptyBorder(0,0,5,0)); int page = 0; for(int i=0;i<size;i+=step) { page++; final int index = i; final JRadioButton rb = new JRadioButton(""+page); final RowFilter<TestModel,Integer> filter = new RowFilter<TestModel,Integer>() { @Override public boolean include(Entry<? extends TestModel, ? extends Integer> entry) { int ei = entry.getIdentifier(); return (index<=ei && ei<index+step); } }; rb.setForeground(Color.BLUE); rb.setUI(ui); rb.setAction(new AbstractAction(""+page) { @Override public void actionPerformed(ActionEvent e) { sorter.setRowFilter(filter); } }); box.add(rb); bg.add(rb); if(i==0) { rb.setSelected(true); sorter.setRowFilter(filter); } } } }} -&jnlp; -&jar; -&zip; **解説 [#uc3887af] 上記のサンプルは、検索サイトなどでよく使われている、PaginationをJTableで行っています。 ただし、ページ数が大量にある場合の処理や、前へ、次へなどの実装は無視して、ある位置から一定の行数だけ表示するフィルタを予め作成し、これを上部のJRadioButton((BasicRadioButtonUIを継承して見た目だけリンク風になるよう変更している))で切り替えるだけになっています。 また、モデルのインデックス順でフィルタリングしているため、ソートを行っても、表示される行の順番が変化するだけになります。 //**参考リンク **コメント [#n7c8e61e] #comment