1/12/2023 0 Comments Tabular formHowever, when table itself is resized typically because the window has resized the columns' preferred widths do not change. When the user explicitly resizes columns, the columns' preferred widths are set such that the user-specified sizes become the columns' new current widths. For an example of setting cell widths based on an approximation of the space needed to draw the cells' contents, see the initColumnSizes method in TableColumn supplies getter and setter methods for the minimum, preferred, and maximum widths of a column, as well as a method for getting the current width. For example, adding the following code to SimpleTableDemo makes its third column bigger than the other columns:Ĭolumn = table.getColumnModel().getColumn(i) ĬtPreferredWidth(100) //third column is biggerĪs the preceding code shows, each column in a table is represented by a This sets both the preferred widths of the columns and their approximate relative widths. To customize initial column widths, you can invoke setPreferredWidth on each of your table's columns. By default, the table's size remains the same, and all columns to the right of the drag point resize to accommodate space added to or removed from the column to the left of the drag point. When the user resizes a column by dragging its right border, then either other columns must change size, or the table's size must change. 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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |