disabling table cell in java

Here when user enter value 3 for a cell in a table, then that cell becomes uneditable


class Testing
{
public void buildGUI()
{
JTable table = new JTable(5,3){
public boolean isCellEditable(int row,int column){
Object o = getValueAt(row,column);
if(o != null && o.equals("3")) return false;
return true;
}
};
JFrame f = new JFrame();
f.getContentPane().add(new JScrollPane(table));
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable(){
public void run(){
new Testing().buildGUI();
}
});
}
}

0 comments:

Post a Comment