The DataGridModel is used by the JDataGrid component, it supports some features such as undo and redo, cell attributes, merge cell, split cell.
Merge Cell
Code Samples:
DataGridModel model = new DefaultDataGridModel(99, 26);
model.merge(new Cell(0, 0, 5, 6));
Split Cell
Code Samples:
DataGridModel model = new DefaultDataGridModel(99, 26);
model.split(new Cell(0, 0, 5, 6));
Undo and Redo
Code Samples:
DataGridModel model = new DefaultDataGridModel(99, 26);
model.addUndoableEditListener(listener);
Cell Attributes
Cell Foreground Code Samples:
DataGridModel model = new DefaultDataGridModel(99, 26);
SimpleAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setForeground(attr, Color.red);
model.setCellAttributes(attr, 0, 0);
Cell Background Code Samples:
DataGridModel model = new DefaultDataGridModel(99, 26);
SimpleAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setBackground(attr, Color.red);
model.setCellAttributes(attr, 0, 0);
Cell Font Code Samples:
DataGridModel model = new DefaultDataGridModel(99, 26);
SimpleAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setBold(attr, true);
StyleConstants.setItalic(attr, true);
StyleConstants.setUnderline(attr, true);
StyleConstants.setStrikeThrough(attr, true);
StyleConstants.setFontFamily(attr, "Monospaced");
StyleConstants.setFontSize(attr, 22);
model.setCellAttributes(attr, 0, 0);
Sort Cell
Code Samples:
DefaultDataGridModel model = new DefaultDataGridModel(99, 26);
model.sort(new Cell(0, 5, 0, 0), true);
Move Cell
Code Samples:
DefaultDataGridModel model = new DefaultDataGridModel(99, 26);
model.move(new Cell(0, 3, 0, 3), new Cell(10, 13, 10, 13));
Add and Remove Rows and Columns
Code Samples:
DefaultDataGridModel model = new DefaultDataGridModel(99, 26);
// add one row at the end
model.addRow(null);
// remove one row
model.removeRow(3);
// add one column at the end
model.addColumn(null);
// remove one column
model.removeColumn(3);