Update content of JPanel on a frame on button click in another frame(在另一个框架中单击按钮时更新框架上 JPanel 的内容)
问题描述
我创建了一个框架 x1,它有一个面板 p1.加载 x1 时,复选框会动态添加到 p1.添加到 p1 的复选框的数量取决于数据库表 (t1) 中满足特定条件的数据值的数量.
I have created a frame x1 which has a panel p1. When x1 is loaded, checkboxes are added dynamically to p1. The number of checkboxes added to p1 depend on the number of data values in the database table(t1) that satisfy a particular criteria.
帧 x1 上有一个按钮 b1.单击 b1 时,会显示另一个框架 x2,其中可以修改数据库表 t1 的数据值.x2 中的更新"按钮更新 t1 以反映对其数据值所做的更改.
There is a button b1 on frame x1. When b1 is clicked,it displays another frame x2 in which data values of the database table t1 can be modified. A button 'update' in x2,updates t1 to reflect the changes made to its data values.
修改后,当 x2 关闭时,我希望框架 x1 中的面板 p1 自动更新以反映对数据库所做的更改,即满足条件的数据值的数量可能在 x2 中的 t1 修改后发生了变化,因此,在 p1 上显示的复选框的数量也可能发生了变化.
After modification,when x2 is closed I want the panel p1 in frame x1 to be updated automatically to reflect the changes made to the database ie the number of data values satisfying the criteria might have changed after modifictaion of t1 in x2 and hence,the number of check boxes to be displayed on p1 might have changed as well.
如何从 x2 刷新和重新加载 x1 中面板 p1 的组件.
How do I refresh and reload the components of panel p1 in x1 from x2.
想知道是否有人可以帮助我解决问题.在此先感谢您,并对问题中的大量文字感到抱歉.
Was wondering if anyone could help me fix the problem. Thanks in advance and sorry about the load of text in the question.
In x2:
private void UPDATEActionPerformed(java.awt.event.ActionEvent evt)
{
//x1 is an object of ParentFrame
ParentFrame f1=new ParentFrame();
f1.fillPanel();
//fillpanel()fills p1 with checkboxes after running validate() and repaint() on it
}
推荐答案
当点击 b1 时,它会显示另一个帧 x2,其中数据值数据库表t1的可以修改
When b1 is clicked,it displays another frame x2 in which data values of the database table t1 can be modified
- 改用 CardLayout
添加到p1的复选框的数量取决于数据的数量数据库表 (t1) 中满足特定条件的值.
The number of checkboxes added to p1 depend on the number of data values in the database table(t1) that satisfy a particular criteria.
确保从 JPanel 中删除当前内容,然后
be sure that current contents from JPanel is removed, then
p1.revalidate();
p1.repaint();
- 会起作用,不要重新创建
JPanel
的新实例,然后你必须将此Objcet添加到JFrame
,然后必须调用验证()
&repaint()
到JFrame
(现在我希望你不要扩展这个容器 :-) - will be works, don't to re_create a new instance of
JPanel
, then you have to add this Objcet to theJFrame
, then have to callvalidate()
&repaint()
toJFrame
(now I hope that you doean't extends this container :-) 改用 CardLayout
不要创建两个或多个
JFrames
,改用JDialog
,don't to create two or more
JFrames
, useJDialog
instead,只创建
JDialog
(setDefaultCloseOperation(JDialog.CLOSE...)
) 一个实例,将此容器重用于父级的另一个操作create
JDialog
(setDefaultCloseOperation(JDialog.CLOSE...)
) only one instance, reuse this container for another action from parent这篇关于在另一个框架中单击按钮时更新框架上 JPanel 的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
修改后,当 x2 关闭时,我希望框架 x1 中的面板 p1 自动更新以反映对数据库,即满足标准的数据值的数量可能在 x2 中修改 t1 后发生了变化,因此,要在 p1 上显示的复选框也可能已更改.
After modification,when x2 is closed I want the panel p1 in frame x1 to be updated automatically to reflect the changes made to the database ie the number of data values satisfying the criteria might have changed after modifictaion of t1 in x2 and hence,the number of check boxes to be displayed on p1 might have changed as well.
本文标题为:在另一个框架中单击按钮时更新框架上 JPanel 的内容


- 未找到/usr/local/lib 中的库 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 获取数字的最后一位 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 转换 ldap 日期 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01