symon symon - 2 months ago 9
Java Question

Removing JTable CellRenderer when radiobutton is deselected

I'm using the following code to apply a CellRender on my JTable password field

JRadioButton HidePW = new JRadioButton("Show Passwords ");
HidePW.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange() == ItemEvent.SELECTED) {
ConnectionsTable.getColumnModel().getColumn(3).setCellRenderer(togglePW);
ConnectionsTable.repaint();
}else{

};
}
});


it is working great, however could someone help me not have this apply when the radio button becomes unselected? is there a simple way to overwrite this custom CellRender or remove it?

Answer

In the else block apply the default cell renderer :

ConnectionsTable.getColumnModel().getColumn(3).setCellRenderer(ConnectionsTable.
                                              getDefaultRenderer(String.class));
Comments