Java, How to refresh JTable in one frame from another frame

橙三吉。 提交于 2019-12-06 15:45:53

maybe a static Method in the AddProduct class that returns the created Product will solve your problem. Take a look at the JOptionPane API for example static String showInputDialog(Object message)

Abhishek Choudhary

You need to work on the JTable model part and then refresh , revalidate will work. Just try some examples of JTable dynamic updates like create TableModel and populate jTable dynamically

The easy way would be to have a method in the main class that fills the table with data and in your actionPerformed method where you are handling adding a new record call that method after a record has been added. That way the main class is handling the update of the table model and the internals of the JTable will handle the repainting of the table. You could even use a method from the UpdateProducts to only update the table if adding a record was successful.

public void actionPerformed(ActionEvent e) { 
        UpdateProduct up = new UpdateProduct();
        if(up.addRecord(ps.getProductByID(15))){ 
          fillTable();
        }
    }

Hope that helps some.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!