

When the table becomes wider or narrower (which might happen when the user resizes the window containing the table), all the column widths change appropriately. Here is typical code for creating a scroll pane that serves as a container for a table:Ĭontainer.add(table.getTableHeader(), BorderLayout.PAGE_START) Ĭontainer.add(table, BorderLayout.CENTER) īy default, all columns in a table start out with equal width, and the columns automatically fill the entire width of the table. If you want to get around these restrictions, you need to implement your own table model, as described in Creating a Table Model. For example, if you are instantiating a set of objects from a database, you might want to query the objects directly for their values, rather than copying all their values into an array or vector. They require that you put all of the table's data in an array or vector, which may not be appropriate for some data.You can see this difference in the Vegetarian column of the previous figure. However, if you use either of the two JTable constructors listed previously, your Boolean data is displayed as a string. For example, if a table column has Boolean data, the table can display the data in a check box. They treat all data types the same (as strings).They automatically make every cell editable.However, these constructors also have disadvantages: The advantage of these constructors is that they are easy to use. JTable(Vector rowData, Vector columnNames).


Java™ Web Start ( download JDK 7 or later).

Click the Launch button to run SimpleTableDemo using
