/* * StyleGridDemo.java * * Copyright 2000 Eliad Technologies, Inc. All Rights Reserved. * * This software is the proprietary information of Eliad Technologies, Inc. */ package example05; import java.awt.*; import java.awt.event.*; import javax.swing.*; import com.eliad.swing.*; import com.eliad.util.*; import com.eliad.model.*; import com.eliad.model.defaults.*; /** * This class demonstrates customizing of the StyleModel. * @author Daniel Rosenblatt * @version 1.0 */ public class StyleGridDemo extends JFrame { private JSmartGrid grid_; public StyleGridDemo() { super("Style Example"); addWindowListener ( new WindowAdapter () { public void windowClosing (WindowEvent evt) { System.exit(0); } } ); DefaultStyleModel styleModel = new DefaultStyleModel(); styleModel.setRenderer( Integer.class, new DefaultStyleModel.NumberRenderer() { public Component getComponent(Object value, boolean isSelected, boolean hasFocus, boolean isEditable, int row, int column, GridContext context) { Component c = super.getComponent(value, isSelected, hasFocus, isEditable, row, column, context); if (value instanceof Integer && ((Integer)value).intValue() < 0) c.setForeground(Color.red); return c; } } ); grid_ =new JSmartGrid(); for (int col = 0; col < grid_.getColumnCount(); col++) { grid_.setColumnWidth(col, 50); for (int row = 0; row < grid_.getRowCount(); row++) { int k=row*grid_.getColumnCount()+col; if ((col+row)%2 != 0) k=-k; grid_.setValueAt(new Integer(k), row, col); } } grid_.setStyleModel(styleModel); JScrollPane js = new JScrollPane(grid_); getContentPane().add(js, BorderLayout.CENTER); pack(); } public static void main(String[] args) { StyleGridDemo sg = new StyleGridDemo(); Dimension big=Toolkit.getDefaultToolkit().getScreenSize(); Dimension small=sg.getSize(); sg.setLocation((big.width-small.width)/2, (big.height-small.height)/2); sg.setVisible(true); } }