I have 2 classes that convert a column into a checkbox.
The problem is that when removing the selected one from a checkbox, the row is still painted, and that affects me in some methods. I need that when removing the selected one to the row the painted one is removed
these are the classes I use:
package Presentacion;
import java.awt.Color;
import java.awt.Component;
import javax.swing.DefaultCellEditor;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
public class Clase_CellEditor extends DefaultCellEditor implements TableCellRenderer{
public final JComponent component = new JCheckBox();
public boolean value = false; // valor de la celda
/** Constructor de clase */
public Clase_CellEditor() {
super( new JCheckBox() );
}
/** retorna valor de celda
* @return */
@Override
public Object getCellEditorValue() {
return ((JCheckBox)component).isSelected();
}
/** Segun el valor de la celda selecciona/deseleciona el JCheckBox
* @param table
* @param value
* @param isSelected
* @param row
* @param column
* @return */
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
//Color de fondo en modo edicion
( (JCheckBox) component).setBackground( new Color(200,200,0) );
//obtiene valor de celda y coloca en el JCheckBox
boolean b = ((Boolean) value).booleanValue();
( (JCheckBox) component).setSelected( b );
return ( (JCheckBox) component);
}
/** cuando termina la manipulacion de la celda
* @return */
@Override
public boolean stopCellEditing() {
value = ((Boolean)getCellEditorValue()).booleanValue() ;
((JCheckBox)component).setSelected( value );
return super.stopCellEditing();
}
/** retorna componente
* @return */
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (value == null)
return null;
return ( (JCheckBox) component );
}
}
and this is the other one
package Presentacion;
import java.awt.Color;
import java.awt.Component;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Efrainrodc
*/
public class Clase_CellRender extends JCheckBox implements TableCellRenderer{
private final JComponent component = new JCheckBox();
/** Constructor de clase */
public Clase_CellRender() {
setOpaque(true);
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
//Color de fondo de la celda
( (JCheckBox) component).setBackground( new Color(167,218,251) );//[167,218,251]
//obtiene valor boolean y coloca valor en el JCheckBox
boolean b = ((Boolean) value).booleanValue();
( (JCheckBox) component).setSelected( b );
return ( (JCheckBox) component);
}
}