简体   繁体   English

在另一个JFrame中使用JButton刷新JTable?

[英]Refresh a JTable using a JButton in another JFrame?

I've created two JFrame s. 我创建了两个JFrame Frame 1 has a JTable and frame 2 has a JButton . 框架1具有JTable ,框架2具有JButton The JTable contains data from a MySQL table. JTable包含来自MySQL表的数据。 What I want to do is this: when I click the JButton in frame 2, the JTable in frame 1 needs to be refreshed. 我想做的是:单击框架2中的JButton时,需要刷新框架1中的JTable How can I do that? 我怎样才能做到这一点?

Let your TableModel export an Action that fires the TableModelEvent appropriate to any changes made. 让您的TableModel导出一个Action ,该Action触发适用于所做任何更改的TableModelEvent Use the Action to construct the button. 使用Action构造按钮。 When the button is clicked and the Action fires, any table listening to the table model will update automatically. 单击该按钮并触发Action时,任何侦听该表模型的表都将自动更新。 There are related examples here and here . 这里这里都有相关的示例。

See also The Use of Multiple JFrames, Good/Bad Practice? 另请参阅使用多个JFrame,良好/不良做法?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM