Java JTable, how to change cell data (write text in)?
        Posted  
        
            by 
                Bob Owuor
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Bob Owuor
        
        
        
        Published on 2012-10-28T23:34:20Z
        Indexed on 
            2012/10/29
            11:01 UTC
        
        
        Read the original article
        Hit count: 188
        
Am looking to change a cell's data in a jtable. How can I do this? When I execute the following code I get errors.
JFrame f= new JFrame();
final JTable table= new JTable(10,5);
TableModelListener tl= new TableModelListener(){
  public void tableChanged(TableModelEvent e){
    table.setValueAt("hello world",2,2);
  }
};
table.getModel().addTableModelListener(tl);
f.add(table);
f.pack();
f.setVisible(true);
I have also tried this below but it still doesn't work. What gives?
table.getModel().setValueAt("hello world",2,2);
        © Stack Overflow or respective owner