# Models

The swingutils.models package offers a collection of useful models for most Swing components that require the use of models.

## List models

### DelegateListModel

This class wraps a Python list object and implements the :class:javax.swing.ListModel interface. You can access as any normal list, but it also fires list events when its contents are modified.

## Table models

### DelegateTableModel

This class wraps a Python list object and implements the :class:javax.swing.table.TableModel interface. All elements of the wrapped list are expected to be lists or tuples (or any other indexed collections). Column names and types are provided in the constructor as a series of 2-tuples:

from java.lang import String, Integer

from swingutils.models.table import DelegateTableModel

model = DelegateTableModel(somedata, ('Name', String), ('Age', Integer), 'Hometown')


As you probably noticed, the last column was not a tuple, but a string. This translates to ('HomeTown', Object). The reason why types are given as Java types is to give the default column renderer a hint for choosing the correct renderer for this column.

### ObjectTableModel

This table model is much more useful than its parent class (:class:~swingutils.models.DelegateTableModel). The contents of the wrapped list object are expected to be objects, and columns are mapped to their attributes. Therefore the constructor expects an series of 3-tuples (name, type, attribute name). You can no longer use the name-only shortcut of only providing the name as a string -- you have to give all three values. You can also supply a callable in place of the attribute name, in which case the callable is called with each object in the list as the argument. The return value of this callable is then used to draw the table cell.

### TableSelectionProxy

This is a utility class that you can use on a table that has an :class:~swingutils.models.table.ObjectTableModel as its model. It tracks the table selection and provides the selectedValue and selectedModelRow bound properties.

## Combo box models

### DelegateComboBoxModel

This is basically the same as :class:~swingutils.models.list.DelegateListModel`, but works as a combo box model.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.