There are two Frame: on the first one there is a table JTable1, on the second, for example, there are several JTextField to fill and one JButton1. Question: how to make it so that by pressing the JButton1 button in JTable1 a new entry is immediately added? I tried a lot of things, but in vain.



    1 answer 1

    You hang ActionListener on a JButton, which reads text from a JTextField, further your values ​​and do a repaint () of the table. But of course it would be better if you gave an example of your code ...

    • I have no workable code. Therefore, I ask. About repaint () - but I can’t directly access the table. - Sergey1991
    • @ Sergey1991: how do the records usually fall into the table? (For example, through TableModel ?) Well, in the same way they should be added from the Listener. - VladD
    • @ Sergey1991: 1. No need to contact the table. Add data to the TableModel , the table will be updated automatically. 2. ActionListener in our case is a function that will be called when a button is pressed. In the general case, a function that will be called upon the occurrence of a condition, for an ActionListener , when an Action is executed. (Read about the Observer pattern at your leisure.) - VladD
    • Those. in this case, the Action will be the addRow function? - Sergey1991
    • @ Sergey1991: not, Action , which is monitored - this is a click on the button. And ActionListener will execute AddRow when the observed Action is executed. - VladD