diff options
Diffstat (limited to 'examples/gnu/classpath/examples/swing/TableDemo.java')
-rw-r--r-- | examples/gnu/classpath/examples/swing/TableDemo.java | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/examples/gnu/classpath/examples/swing/TableDemo.java b/examples/gnu/classpath/examples/swing/TableDemo.java index 92f4cc758..1fbf2de53 100644 --- a/examples/gnu/classpath/examples/swing/TableDemo.java +++ b/examples/gnu/classpath/examples/swing/TableDemo.java @@ -45,7 +45,9 @@ import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; +import javax.swing.table.DefaultTableColumnModel; import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableColumn; /** * Displays the editable table. The first column consists of check boxes. @@ -62,7 +64,7 @@ public class TableDemo extends JFrame /** * The initial column count for this table. */ - static int cols = 8; + static int cols = 7; /** @@ -112,11 +114,13 @@ public class TableDemo extends JFrame } /** - * The column name. + * The column name, as suggested by model. This header should not be + * visible, as it is overridden by setting the header name with + * {@link TableColumn#setHeaderValue} in {@link TableDemo#createContent}. */ public String getColumnName(int column) { - return "Demo "+column; + return "Error "+column; } /** @@ -137,7 +141,7 @@ public class TableDemo extends JFrame * The table being displayed. */ JTable table = new JTable(); - + /** * The table model. */ @@ -171,7 +175,6 @@ public class TableDemo extends JFrame { JPanel p = new JPanel(); p.setLayout(new BorderLayout()); - table.setModel(model); values = new Object[rows][]; for (int i = 0; i < values.length; i++) { @@ -183,6 +186,27 @@ public class TableDemo extends JFrame values [i][0] = i % 2 == 0? Boolean.TRUE : Boolean.FALSE; } + table.setModel(model); + + // Make the columns with gradually increasing width: + DefaultTableColumnModel cm = new DefaultTableColumnModel(); + for (int i = 0; i < cols; i++) + { + TableColumn column = new TableColumn(i); + + // Showing the variable width columns. + int width = 100+20*i; + column.setPreferredWidth(width); + + // If we do not set the header value here, the value, returned + // by model, is used. + column.setHeaderValue("Width +"+(20*i)); + + cm.addColumn(column); + } + + table.setColumnModel(cm); + // Create the table, place it into scroll pane and place // the pane into this frame. JScrollPane scroll = new JScrollPane(); @@ -209,4 +233,4 @@ public class TableDemo extends JFrame frame.validate(); frame.setVisible(true); } -}
\ No newline at end of file +} |