|
SpanDrawer |
Top Previous Next |
SpanDrawer is responsible for drawing the spanned cells of a JTable, by querying a SpanModel in order to find out which cells to span.
SpanDrawer has three constructors:
SpanDrawer();
SpanDrawer(JTable table);
SpanDrawer(JTable table, SpanModel spanModel);
You can use the third constructor to specify the associated table and the span model to use. Nevertheless, you can assign these variables later by calling:
public void setTable(JTable newTable);
public void setSpanModel(SpanModel newSpanModel);
If you do not specify a span model in the constructor, a DefaultSpanModel is created, through which spanned cells can be dynamically added/removed.
You can get an instance of the span model with:
public SpanModel getSpanModel();
Cell spanning is not enabled by default when you first create a SpanDrawer instance. In order to enable cell spanning, use:
public void setUseSpan(boolean useSpan);
You can also determine if cell spanning is enabled with:
public boolean getUseSpan();
AdvancedJTable creates an internal SpanDrawer object upon initialization, which is used to draw the spanned cells. In AdvancedJTable, there are methods for creating, setting and getting the span drawer to use:
protected SpanDrawer createSpanDrawer();
public void setSpanDrawer(SpanDrawer drawer);
public SpanDrawer getSpanDrawer();
Example: Manipulate AdvancedJTable's SpanDrawer object.
AdvancedJTable table = new AdvancedJTable();
//initialize the table with some data here.
...
...
SpanDrawer drawer = table.getSpanDrawer();
DefaultSpanModel dsm = (DefaultSpanModel) drawer.getSpanModel();
CellSpan cellSpan = new CellSpan(0, 0, 0, CellSpan.ALL_COLUMNS);
dsm.addCellSpan(cellSpan);
You can also use SpanDrawer in your own JTable subclass by using appropriate code. To find out more see the Appendix.