table.getColumnModel().getColumn(3).setCellEditor(new CustomTableCellRenderer(new JCheckBox(),Name));
table.getColumnModel().getColumn(3).setCellRenderer(new CustomTableCellRenderer3());
this is my celleditor class;;;;;;;;;;;;;;;;;;;;;;
package moxaclient;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.DefaultCellEditor;
import javax.swing.JCheckBox;
import javax.swing.JTable;
public class CustomTableCellRenderer extends DefaultCellEditor implements ItemListener{
private static final long serialVersionUID = 1L;
private JCheckBox checkBox;
private JTable table1;
private int row;
private int column;
Object abc="null";
private String Name;
Component comm=null;
public CustomTableCellRenderer(JCheckBox checkBox,String name2) {
super(checkBox);
this.checkBox = checkBox;
this.checkBox.addItemListener(this);
this.Name=name2;
}
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected,int row, int column)
{
Component comp = super.getTableCellEditorComponent(table, value, isSelected, row, column);
this.row = row;
this.table1=table;
this.column = column;
checkBox.setSelected((Boolean)value);
return super.getTableCellEditorComponent(table, value, isSelected,row, column);
}
public void itemStateChanged(ItemEvent e)
{
this.fireEditingStopped();
//System.out.println("Item Changed " + row + " value is: " + checkBox.isSelected());
//System.out.println("Item Changed " + column + " value is: " + checkBox.isSelected());
String Sensor =(String) table1.getValueAt(row, 0);
Double Value =(Double) table1.getValueAt(row, 1);
String Date =(String) table1.getValueAt(row, 2);
Boolean select=(Boolean) table1.getValueAt(row,3);
if (Boolean.TRUE.equals(select))
{
abc += Sensor+"\t"+Value+"\t"+Name+"\t"+Date+"\t";
}
This is my cellrenderer class ;;;;;;
package moxaclient;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
public class CustomTableCellRenderer3 extends DefaultTableCellRenderer {
private static final long serialVersionUID = 1L;
JTable table1=null;
DefaultTableModel model;
public CustomTableCellRenderer3() {
// TODO Auto-generated constructor stub
}
public CustomTableCellRenderer3(JTable table,DefaultTableModel model1) {
this.table1=table;
this.model=model1;
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col)
{
Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
Boolean last=(Boolean)model.getValueAt(row,3); ////// i think the code is not right, please help me with code
if(last)
{
color red here
}
//return null;
}
}