Source Code : Creating a Custom Table Cell Editor 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

Creating a Custom Table Cell Editor in a JTable Component

 

import java.awt.Component;

import javax.swing.AbstractCellEditor;
import javax.swing.JComponent;
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 {

  JComponent component = new JTextField();

  public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
      int rowIndex, int vColIndex) {

    ((JTextField) component).setText((String) value);

    return component;
  }

  public Object getCellEditorValue() {
    return ((JTextField) component).getText();
  }
}

   
  

Thank with us