Source Code : Preventing Invalid Values in a Cell in a JTable Component

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Preventing Invalid Values in a Cell in a JTable Component

 
 
import java.awt.Component;

import javax.swing.AbstractCellEditor;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableColumn;

public class Main {
  public static void main(String[] argv) throws Exception {
    JTable table = new JTable();
    TableColumn col = table.getColumnModel().getColumn(0);
    col.setCellEditor(new MyTableCellEditor());
  }
}

class MyTableCellEditor extends AbstractCellEditor implements TableCellEditor {
  public boolean stopCellEditing() {
    String s = (String) getCellEditorValue();

    return super.stopCellEditing();
  }
  JTextField field = new JTextField();
  public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
   
    return field;
  }

  public Object getCellEditorValue() {
    return null;
  }
}

   
  

Thank with us