[Original] Rendering of the form of forms (code demonstration)
/ ** * @ (#) editorrenderer.java * * Copyright 2004 OpenSource Develop Team. All Rights Reserved. * /
// packagepackage com.opensource.table;
// Import Classesimport javax.swing.table.tableCellrenderer; import javax.swing.table.defaulttableCellrenderer; import javax.swing. *; import java.awt. *;
/ ** * A table renderer. The role is to make the color of the selected row and the color of other rows. * * @Author: ODT * @see: DefaultCellRenderer * @version: 1.0 22/04/2004 * @since: 1.3 * / public class EditorRenderer extends DefaultTableCellRenderer {// table has JCheckBox internal components JCheckBox checkBox = new JCheckBox (); JTable TABLE;
Public editorrenderer (jtable table) {this.table = table;}
public Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {if (row == table.getSelectedRow ()) {checkBox.setBackground (new Color (187, 137, 233)); } else {checkBox.setBackground (new Color (244, 244, 128));} checkBox.setSelected (((Boolean) value) .booleanValue ()); checkBox.setHorizontalAlignment (JLabel.CENTER); return checkBox;}}