| 1 |
package org.guha.rcdk.view.table; |
| 2 |
|
| 3 |
import org.guha.rcdk.util.TablePacker; |
| 4 |
|
| 5 |
import javax.swing.*; |
| 6 |
import javax.swing.table.TableModel; |
| 7 |
|
| 8 |
|
| 9 |
public class MyTable extends JTable { |
| 10 |
private TablePacker packer = null; |
| 11 |
|
| 12 |
/** |
| 13 |
* Constructs a <code>JTable</code> to display the values in the two dimensional array, |
| 14 |
* <code>rowData</code>, with column names, <code>columnNames</code>. |
| 15 |
* <code>rowData</code> is an array of rows, so the value of the cell at row 1, |
| 16 |
* column 5 can be obtained with the following code: |
| 17 |
* <p/> |
| 18 |
* <pre> rowData[1][5]; </pre> |
| 19 |
* <p/> |
| 20 |
* All rows must be of the same length as <code>columnNames</code>. |
| 21 |
* <p/> |
| 22 |
* |
| 23 |
* @param rowData the data for the new table |
| 24 |
* @param columnNames names of each column |
| 25 |
*/ |
| 26 |
public MyTable(Object[][] rowData, Object[] columnNames) { |
| 27 |
super(rowData, columnNames); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Constructs a <code>JTable</code> that is initialized with |
| 32 |
* <code>dm</code> as the data model, a default column model, |
| 33 |
* and a default selection model. |
| 34 |
* |
| 35 |
* @param dm the data model for the table |
| 36 |
* @see #createDefaultColumnModel |
| 37 |
* @see #createDefaultSelectionModel |
| 38 |
*/ |
| 39 |
public MyTable(TableModel dm) { |
| 40 |
super(dm); |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
public void pack(int rowsIncluded, boolean distributeExtraArea) { |
| 45 |
packer = new TablePacker(rowsIncluded, distributeExtraArea); |
| 46 |
if (isShowing()) { |
| 47 |
packer.pack(this); |
| 48 |
packer = null; |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
public void addNotify() { |
| 53 |
super.addNotify(); |
| 54 |
if (packer != null) { |
| 55 |
packer.pack(this); |
| 56 |
packer = null; |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
} |