Example usage for javax.swing.table AbstractTableModel setValueAt

List of usage examples for javax.swing.table AbstractTableModel setValueAt

Introduction

In this page you can find the example usage for javax.swing.table AbstractTableModel setValueAt.

Prototype

public void setValueAt(Object aValue, int rowIndex, int columnIndex) 

Source Link

Document

This empty implementation is provided so users don't have to implement this method if their data model is not editable.

Usage

From source file:SetValueAtToSetValue.java

public SetValueAtToSetValue() {
    final AbstractTableModel model = new MyModel();
    final JTable table = new JTable(model);
    getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
    model.setValueAt(new Integer(1), 0, 0);

    JButton button = new JButton("Increment selected cell");
    getContentPane().add(button, BorderLayout.SOUTH);
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int row = table.getSelectedRow();
            int column = table.convertColumnIndexToModel(table.getSelectedColumn());
            int currentValue = ((Integer) model.getValueAt(row, column)).intValue();
            model.setValueAt(new Integer(currentValue + 1), row, column);
        }//from ww w.  jav  a  2 s. co m
    });

    pack();
}

From source file:Main.java

public Main() {
    final AbstractTableModel model = new MyModel();
    final JTable table = new JTable(model);
    getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
    model.setValueAt(new Integer(1), 0, 0);

    JButton button = new JButton("Increment selected cell");
    getContentPane().add(button, BorderLayout.SOUTH);
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int row = table.getSelectedRow();
            int column = table.convertColumnIndexToModel(table.getSelectedColumn());
            int currentValue = ((Integer) model.getValueAt(row, column)).intValue();
            model.setValueAt(new Integer(currentValue + 1), row, column);
        }/*w w w  .j  av a  2s .  co  m*/
    });

    pack();
}