JIDE 3.4.0

com.jidesoft.grid
Interface StyleModel

All Known Subinterfaces:
StyleTableModel
All Known Implementing Classes:
AbstractStyleTableModel, AggregateTableModel, AutoFilterUtils.AutoFilterRowTableModel, BatchedCrudTableModelWrapper, CachedTableModel, CalculatedHeaderTableModel, CalculatedTableModel, CornerTableModel, CrudTableModelAdapter, DataTableModel, DefaultColumnTableModelWrapper, DefaultStyleTableModel, DefaultTableModelWrapper, FeedItemTableModel, FilterableAggregateTableModel, FilterableTableModel, FilterableTreeTableModel, HeaderTableModel, JoinTableModel, LuceneFilterableTableModel, SortableAggregateTableModel, SortableTableModel, SortableTreeTableModel, TableModelWrapperImpl, TransposeTableModel

public interface StyleModel

StyleModel provides a way to use CellStyle along with any TableModel. Below is a typical way of using it.

 class StyleTableModel extends AbstractTableModel implements StyleModel {
     // all other table model related methods
 

static CellStyle _cellStyle;

public CellStyle getCellStyleAt(int row, int column) { // The code below will make all cell center alignment and create stripes in the table.

_cellStyle.setHorizontalAlignment(SwingConstants.CENTER);

if (row % 2 == 0) { _cellStyle.setBackground(BACKGROUND1); } else { _cellStyle.setBackground(BACKGROUND2); } return _cellStyle; }

public boolean isCellStyleOn() { return true; } }

All you need to do is to return a desired CellStyle at getCellStyleAt(int, int) method. If the styles are static (not change with value change) such as stripe pattern or grid pattern, all you need is to use the row and column index that are passed in. See the example above. It will create a stripe pattern.
If the styles are dynamically changing with the cell value, you call getValueAt(row, column) to get the value and return different style based on the cell value. For example, if the value is negative, returns red foreground cell style.

You need to be aware of the performance. Since getCellStyleAt() will be called for every table repaint, you should make this method as efficient as possible. A typical way is to use the same CellStyle instance again and again by setting different value. Again, see the example code above. Or if the table only used several predefined styles, you can define them all as static final fields and return them accordingly.

In the case you want to turn off the whole style thing or you know that getCellStyleAt() will return null in all cases, it will be better to return false in isCellStyleOn() method because if it's false, the code in CellStyleTable won't even bother calling getCellStyleAt().


Method Summary
 CellStyle getCellStyleAt(int rowIndex, int columnIndex)
          Gets the cell style at the specified row and column.
 boolean isCellStyleOn()
          Checks if the style is on.
 

Method Detail

getCellStyleAt

CellStyle getCellStyleAt(int rowIndex,
                         int columnIndex)
Gets the cell style at the specified row and column.

Parameters:
rowIndex - the row index
columnIndex - the column index
Returns:
CellStyle object.

isCellStyleOn

boolean isCellStyleOn()
Checks if the style is on. The CellStyleTable will ignore all the CellStyles defined in this model if this method returns false.

Returns:
true if style is on. Otherwise false.

JIDE 3.4.0