Thanks for this answer, I look in the table and I never remember to go to
the TableModel.
 
Onether question. Know I have the Table with the cells editable. 
If I chose another column the setValueAt is called.
If I press the button the setValueAt is not called.
If I go to the TextArea the setValueAt is not called. 
if I close the Frame the setValueAt is not called.
This isn't suposed? 
 
Simple code. I'm seeing just the output.
 
import java.awt.BorderLayout; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
 
import javax.swing.*; 
import javax.swing.table.AbstractTableModel;
 
class MyTableModel extends AbstractTableModel { 
    int nRows = 5; 
    public int getRowCount() {
        return nRows; 
    } 
 
    public int getColumnCount() {
        return 4; 
    } 
                
    public Object getValueAt(int arg0, int arg1) {
        return new Integer(arg0*arg1); 
    } 
    
    void IncrementRow() {
        System.out.println("IncrementRow()");
        nRows++; 
    } 
    
    public boolean isCellEditable(int nRow, int nCol) {
        System.out.println("isCellEditable(int nRow, int nCol)");
        return true;
    }
 
    public void setValueAt(Object arg0, int arg1, int arg2) {
        System.out.println("setValueAt(Object arg0, int arg1, int arg2)");
    }
} 
 
public class Main { 
    static JFrame m_frame; 
    public static void main(String[] ARGS) {        
        m_frame = new JFrame("Teste"); 
        m_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
        m_frame.getContentPane().setLayout(new BorderLayout()); 
            
        final JTable table = new JTable(); 
        
        final MyTableModel myTableModel = new MyTableModel(); 
        table.setModel(myTableModel); 
 
        final JScrollPane scrollPane = new JScrollPane(table); 
            
        m_frame.getContentPane().add(scrollPane, BorderLayout.CENTER); 
 
        JButton bt = new JButton("XXX"); 
        bt.addActionListener(new ActionListener(){ 
            public void actionPerformed(ActionEvent arg0) { 
                myTableModel.IncrementRow(); 
                myTableModel.fireTableDataChanged();
            } 
        }); 
 
        m_frame.getContentPane().add(bt, BorderLayout.NORTH);
        
        m_frame.getContentPane().add(new JTextField(), BorderLayout.SOUTH); 
            
        m_frame.pack(); 
        m_frame.setVisible(true); 
    } 
} 
 
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to