在一个框架上更新JPanel的内容,单击另一个框架上的按钮 [英] Update content of JPanel on a frame on button click in another frame

查看:126
本文介绍了在一个框架上更新JPanel的内容,单击另一个框架上的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个带有面板p1的框架x1.加载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
    • use CardLayout instead
    • 添加到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的新实例,那么您必须将此对象添加到JFrame,然后必须调用validate()& repaint()JFrame(现在希望您不要扩展此容器:-)
        • will be works, don't to re_create a new instance of JPanel, then you have to add this Objcet to the JFrame, then have to call validate() & repaint() to JFrame (now I hope that you doean't extends this container :-)
        • 修改后,当x2关闭时,我希望框x1中的面板p1自动更新以反映对x2所做的更改 数据库,即满足条件的数据值的数量 在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.

          • 改用 CardLayout

            不要创建两个或多个JFrames,请改用JDialog

            don't to create two or more JFrames, use JDialog instead,

            仅创建一个实例JDialog(setDefaultCloseOperation(JDialog.CLOSE...)),将此容器重用于父级的另一操作

            create JDialog (setDefaultCloseOperation(JDialog.CLOSE...)) only one instance, reuse this container for another action from parent

            这篇关于在一个框架上更新JPanel的内容,单击另一个框架上的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆