To use TableControl you need to call the following methods:
setRecordClass(Class<T> recordClass): set the class of record (java POJO class) that will be displayed in the table. TableView will use this information to reflectively create new instance when insert button is clicked.
setController(TableController<T> controller): set the controller that is responsible to load data, additionally to delete, update and insert data. TableController is an abstract class. You need to extend it and implement
loadData()methods. If you want your table to have delete and save capabilities, you need to override
delete()methods. There are also several callback methods that could be overriden to customize TableControl’s default behaviour.
addColumn(TableColumn<T, ?>... columns): add columns to table.
IMPORTANT: If the record class overrides Object’s
equals(Object object) and
hashCode() methods, TableView might not refresh cell’s value properly. Unless you take all records properties into account in the equals method.
To change default maximum row for all TableControls in your application, change the value of
To change style of changed row, check tiwulfx.css
Column that display value from persistent record (POJO) extends BaseColumn. The first/sole generic type should match with TableControl’s record class. The column needs propertyName parameter in its constructor. The propertyName parameter should match with the getter and setter methods of the record class. This way the column knows what get or set methods to call. For example, if the record class is Person and it has name property, the code to create the name column will be:
TextColumn<Person> clmName = new TextColumn<>("name");
Columns that able to hold various data types i.e: ComboBoxColumn, have 2 generic type. The first is the record class and the second is the data type of property that the column will display.
This column can only handle String data type.
ComboBoxColumn could store any objects and display them as String. The second generic type is the class of data type of the column. For example, Person’s gender data type is char: ‘f’ for female and ‘m’ for male. Values that will be saved in database is either ‘f’ or ‘m’. But we need to display them as ’female’ or ‘male’ in user interface.
addItem(String label, T object) method is provided to address this issue.
ComboBoxColumn<Person, Character> clmGender = new ComboBoxColumn<>("gender"); clmGender.addItem("Male", 'm'); clmGender.addItem("Female", 'f');
There is also
setRequired(boolean) which need to be set to FALSE if we want to provide blank item in combobox’s list for user to unspecify value.
NumberColumn<S extends Object, T extends Number>
NumberColumn only accepts digit input. If the T generic type is Double or BigDecimal, it also accept decimal character (dot or comma) depends on the Locale. The class of the data type needs to be specified in NumberColumn’s constructor. Below is an example on how to create Integer and Double columns.
NumberColumn<Person, Integer> clmVersion = new NumberColumn<>("version", Integer.class); NumberColumn<Person, Double> clmWeight = new NumberColumn<>("weight", Double.class);
LookupColumn<S, T> extends BaseColumn<S, T>
LookupColumn usually is used to display property that is stored in foreign table. It can displays suggestion list as well as lookup window. The suggestion list will be shown as user type in it. You can specify the delay time by calling
LookupColumn needs additional parameter besides propertyName which is lookupPropertyName. lookupPropertyName corresponds with propertyName of the object that is referred by the record. For example, Person table has many-to-one relationship with Insurance table therefore Person POJO has insurance property. To display insurance’s code that referred by a person in Person TableView, we will use LookupColumn as follow:
LookupColumn<Person, Insurance> clmInsurance = new LookupColumn<>("insurance", "code");
LookupColumn will not be able to display suggestion or lookup window without a controller that handles communication with database. Call
setLookupController(LookupFieldController<T> lookupController) to set the controller.
Press Ctrl+Space to forcibly display suggestion list and press Ctrl+Enter to display lookup window.
CheckBoxColumn can only display Boolean data. Call
setRequired(false) to make CheckBox cell has 3 states: TRUE, FALSE and NULL.
This column use DateControl that is based on Christian Schudt’s Date Picker. DateControl has key bindings to change the date easily. Use Up/Down to change Date, Ctrl + Up/Down to change month and Ctrl + Shift + Up/Down to change year.
Unlike the previous columns, TickColumn doesn’t display record’s value. It doesn’t extends BaseColumn. Cells of this column contain checkboxes for user to tick/untick particular rows. To get the list of ticked row, call
getTickedRecords(). To get the list of unticked row call
getUntickedRecords(). Developer can also call
setDefaultTicked(boolean) method to set the default behaviour.