List of usage examples for javax.swing.table AbstractTableModel setValueAt
public void setValueAt(Object aValue, int rowIndex, int columnIndex)
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(); }