Diamond Grid Overview Begin | Previous | Next
Drop-in replacement to JTable | Adding styles is easy

Drop-in replacement to JTable
Since Diamond Grid (DsGrid) extends the builtin JTable, you can easily convert an existing application using JTable to one that can use all of the advanced features of Diamond Grid by changing one line of code. For example, if you had the following:
JTable table = new JTable();
change it to
DsGrid table = new DsGrid();

Your existing code will continue to work and now you can begin to use add in some of the new features. For those new to JTable, the following are some of the features of DsGrid that are provided by the base JTable implementation:

  • setting row height (individual row and uniform size)
  • setting column width
  • setting column height
  • custom displays of data using cell renderers and cell editors
  • showing horizontal/vertical grid lines and changing the color
Adding styles to your data is easy and powerful.
grid.getColumns( 0, 0 ).setForeground( Color.blue );
grid.getRows( 1, 1 ).setFontBold( true );
grid.getCellAt( 0, 0 ).setFont( new Font( "serif", Font.ITALIC, 14 ) );
grid.getCellAt( 2, 0 ).setFontStrikeThrough( true );
grid.getCellAt( 3, 0 ).setFontUnderline( DsConstants.SINGLE );
grid.spanCells( 2, 1, 1, 2 );
grid.getCellAt( 2, 1 ).setBackground( Color.yellow );
grid.getCellAt( 2, 1 ).setHorizontalAlignment( DsCell.CENTER );
grid.getCellAt( 3, 1 ).setWordWrap( true );
grid.getCellAt( 3, 1 ).setValue( "Word wrap is available" );
Color c1 = new Color( 180, 235, 255 );
Color c2 = new Color( 130, 180, 250 );
GradientPaint p = new GradientPaint( 0, 0, c1, 0, 15, c2, true );
grid.getCellAt( 3, 1 ).setBackground( p );
grid.setRowHeight( 3, 30 );
grid.setColumnWidth( 1, 80 );
grid.setColumnHorizontalAlignment( 2, DsGrid.RIGHT );
grid.getCells( 0, 1, 1, 2 ).outline( Color.green, DsConstants.DASH, 2 );
grid.getCellAt( 3, 2 ).setBorderStyle( DsCell.DOUBLE_LINE );
grid.getCellAt( 3, 2 ).setBorderLineColor( Color.red );
grid.getCellAt( 3, 2 ).setBorderLineWidth( 2 );
grid.getCellAt( 3, 2 ).setBorderLines( DsCell.BORDER_OUTLINE );
grid.getCellAt( 3, 0 ).setBorderStyle( DsCell.ETCHED );
grid.getCellAt( 3, 0 ).setBackground( Color.lightGray );
grid.getCellAt( 3, 0 ).setHorizontalAlignment( DsCell.CENTER );
grid.getCellAt( 3, 0 ).setVerticalAlignment( DsCell.CENTER );

Font f = new Font("Dialog", Font.BOLD, 14);
grid.getColumnHeader().getProperties().setTextStyle( DsGrid.RAISED );
grid.getColumnHeader().getProperties().setFont( f );
grid.getRowHeader().getProperties().setTextStyle( DsGrid.RAISED );
grid.getRowHeader().getProperties().setFont( f );
Copyright 2003 Diamond Edge, Inc. All rights reserved.