
Reordering events as the model will be queried in its own coordinate So, when writing a TableModel, it is not necessary to listen for column Internally and converts its column indices before querying the model. This does not affect the implementation of the model at all: when theĬolumns are reordered, the JTable maintains the new order of the columns View's columns appear in a different order to the columns in the model. Necessarily the same indexes used by the model.īy default, columns may be rearranged in the JTable so that the The column and row indexes returned by various JTable methodsĪre in terms of the JTable (the view) and are not

The JTable simply takes a tabular range of cellsĪnd uses getValueAt(int, int) to retrieve the The JTable uses integers exclusively to refer to both the rows and the columns The columns in the display to use specialized renderers and editors. Gives a number of complete examples of JTable usage,Ĭovering how the JTable can be used to provide anĮditable view of data taken from a database and how to modify The "TableExample" directory in the demo area of the source distribution Or the DefaultTableModel is to use the AbstractTableModelĪs the base class for creating subclasses and the DefaultTableModel Internal representation that best suits the data.Ī good rule of thumb for deciding whether to use the AbstractTableModel In more efficient applications because the model is free to choose the JTable directly, as in the example above. TableModel interface so that the data can be passed to the It is also possible to wrap the data in the methods of the The DefaultTableModel is a model implementation that When designing applications that use the JTable it is worth payingĬlose attention to the data structures that will represent the table's data. For example: setAutoCreateRowSorter(true). You can set up a row sorter in either of two ways: To enable sorting and filtering of rows, use a View (outside of a JScrollPane) and want the headerĭisplayed, you can get it using getTableHeader() and Note that if you wish to use a JTable in a standalone Invoke setAutoResizeMode(int) with AUTO_RESIZE_OFF. Byĭefault, a JTable will adjust its width such thatĪ horizontal scrollbar is unnecessary. JTables are typically placed inside of a JScrollPane. JScrollPane scrollpane = new JScrollPane(table) TableModel dataModel = new AbstractTableModel() For example, to set up a table with 10 rows and 10 The JTable is used to display and edit regular two-dimensional tablesįor task-oriented documentation and examples of using JTable.įacilities that make it possible to customize its rendering and editingīut provides defaults for these features so that simple tables can be
