Update JTable cells in real time

0

Can the cells of a Jtable be updated while it is on the screen? Type opens the window that has the JTable and it is written in it and then with the info that you put before it, it fills other cells. Is that possible?

    
asked by Mary 09.01.2018 в 14:52
source

1 answer

1

You can try this way to do it where you create an object of a table and within this object is the function of cell editing where you send the row and column with a button to activate the functionality

public class TestTabla {

boolean bandera = false;

public void create() {
    JTable tabla = new JTable(2, 2) {

       public boolean isCeldaEditable(int fila, int columna) {
            if (bandera) {
                return false;
            }
            return true;
        }
    };
    JFrame f = new JFrame();
    JButton boton = new JButton("Disable");
    boton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            bandera = true;
        }
    });
    f.setLayout(new FlowLayout());
    f.add(new JScrollPane(tabla));
    f.add(boton);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            new TestTable().create();
        }
    });
}
    
answered by 09.01.2018 в 16:20