|
|
One of the more powerful Droplets GUI components is the Table, a grid of columns and rows which displays complex sets of data to end-users. Tables can present static information; dynamic information that is automatically scrolled across the visible GUI, or can serve as a set of hyperlinks to outside URLs. It also contains headers and a vertical scrollbar -- both of which can be made either visible or invisible. Every Table requires the use of a TableModel to manage the data to be displayed within the Table. This tutorial focuses on the basics required to build any Table. Consult the Java API for more detailed information on creating automatic, timed scrolling of data across the Table, or the Droplets Developer Zone Training Course. The basic steps in implementing a table within your Droplets applications are as follows: 1. Import the table package with your declarations:
2. Create two variables within your window class (Frame or Dialog) that represent the Table and the Table Model, respectively:
3. Create a Table Model class, which will provide the Table with its data: In order to populate the Table with its data, your Table Model class will have to include the following three methods:
You will of course need to implement each of these methods so that it provides the Droplets Client with sufficient information on the format and population of the Table. getModelSize() should return the exact number or rows and columns within the visible Table. This function returns a TableDimension two integers, the first indicating the number of rows and the second the number of columns. getColumnLabel() should include logic for defining the labels provided for each individual column in the Table component, while getCellValue() indicates the individual string values for each of the Table's cells. The CellCoords argument for getCellValue() represents the cell whose data is being requested. CellCoords is a class that contains two integers, representing the row and column location of a given cell. Use getRow() and getColumn(), respectively, to access them. 4. Within your Window class' addAllComponents() function, add the Table to the GUI layout Below is an example of a method that defines the Table's layout within the window panel. Consult the GUI Layout Tutorial for details of each of the layout parameters shown below:
5. Generate the Table within your window's start() method: This involves calling two methods of the Table component, shown below. start() tells the Droplet Client that the Table data is ready to be queried--at this point the methods of the Table model will be called to populate and format the Table. setRectangularSelection
indicates which row of the Table
is selected by default. Setting the parameters as we have done below
indicates that the first row is selected at start-up.
protected
void
start() These
are the most basic elements necessary to the creation of a Droplets Table.
In order to create events based on Table selections, you will also have
to implement a TableModelListener.
To indicate that data has been changed and the Table should be requeried,
you will need to call the fire...Event
methods of the TableModel. Consult the Droplets
Java API for details on this and other advanced Table features. |