StyleModel

Top  Previous  Next

 

A collection of Styles is kept in a StyleModel.

StyleModel iterates through its collection of styles to apply them to the Component being drawn using the method:

 

public void applyStyles(java.awt.Component c, javax.swing.JTable table, int row, int column);

 

StyleModel also includes methods for managing its internal styles list:

 

public void addStyle(Style newStyle);

public void clearStyles();

public Style getStyle(int index);

public Style[] getStyles();

public void insertStyle(Style newStyle, int index);

public void removeStyle(Style style);

 

DefaultStyleModel is the default style model implementation. An instance of it is created and used by AdavancedJTable.

AdavancedJTable defines methods for creating, getting and setting the StyleModel:

 

protected StyleModel createDefaultStyleModel();

public StyleModel getStyleModel();

public void setStyleModel(StyleModel styleModel);

 

If you want to use a StyleModel in your custom JTable, you should override the method:

 

public Component prepareRenderer(TableCellRenderer renderer, int row, int column);

 

to look like:

 

public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {

       Component c = super.prepareRenderer(renderer, row, column);

       styleModel.applyStyles(c, this, row, column);

       return c;

}