View Javadoc

1   /*
2   
3   nextobjects Copyright (C) 2001-2005 Emmanuel Florent
4   
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by the
7   Free Software Foundation; either version 2 of the License, or (at your
8   option) any later version.
9   
10  This program is distributed in the hope that it will
11  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12  of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13  PURPOSE. See the GNU General Public License for more details.
14  
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc., 59
17  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  
19  */
20  package org.devaki.nextobjects.ui.components;
21  import javax.swing.JTable;
22  /***
23   * This class overwrite the 'JTable' component
24   */
25  public class CustomTable extends JTable
26  {
27      /***
28       * Construct a 'CustomTable' object
29      * @param autoResize setAutoResizeMode
30      * @param selectionMode setSelectionMode
31      * @param reorderingAllowed setReorderingAllowed
32      * @param resizingAllowed setResizingAllowed
33      */
34      public CustomTable(
35          final boolean autoResize,
36          final int selectionMode,
37          final boolean reorderingAllowed,
38          final boolean resizingAllowed)
39      {
40          // Define if resize of columns is automatic or not
41          if (!autoResize)
42          {
43              this.setAutoResizeMode(CustomTable.AUTO_RESIZE_OFF);
44          }
45          // Define the selection mode for the rows
46          this.getSelectionModel().setSelectionMode(selectionMode);
47          // Specify if it is allowed to reorder colums
48          this.getTableHeader().setReorderingAllowed(reorderingAllowed);
49          // Specify if it is allowed to resize colums
50          this.getTableHeader().setResizingAllowed(resizingAllowed);
51      }
52      /***
53       * Set the selected row in the jTable
54       * @param i index of the row
55       */
56      public final void setSelectedRow(final int i)
57      {
58          this.getSelectionModel().removeSelectionInterval(
59              0,
60              this.getRowCount() - 1);
61          this.getSelectionModel().addSelectionInterval(i, i);
62      }
63  }