How can I disable selection of ("grey out") several cells in a column of a JTable according to the value of the cells?

Scott Stanchfield

You can "disable" the cells by setting "enabled" to false in your table cell renderer. For example:

public class MyTCRenderer 
    extends JLabel
    implements TableCellRenderer {

    public Component getTableCellRendererComponent(
        JTable table, Object value,
        boolean isSelected, boolean hasFocus,
        int row, int column) {
        
        if (value.equals("disable me")) {
            setEnabled(false);
        }
        else
            setEnabled(true);
            
        setText((String)value);
        // other stuff...
    }
}
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact