![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e949. Packing a JTable ComponentThis example demonstrates how to adjust the preferred size of aJTable
to be just large enough to accommodate the preferred size of all
cells.
int rows = 10; int cols = 5; JTable table = new JTable(rows, cols) { // Override this method so that it returns the preferred // size of the JTable instead of the default fixed size public Dimension getPreferredScrollableViewportSize() { return getPreferredSize(); } }; // Allow columns to be resized table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // Add data... // These packing methods are defined in e950 Packing a Column of a JTable Component // and e913 Setting the Height of a Row in a JTable Component packColumns(table, 2); packRows(table, 0);
e951. Setting Grid Line Properties in a JTable Component e952. Setting the Gap Size Between Cells in a JTable Component
© 2002 Addison-Wesley. |