Update content of JPanel on a frame on button click in another frame

。_饼干妹妹 提交于 2019-12-01 18:46:40

When b1 is clicked,it displays another frame x2 in which data values of the database table t1 can be modified

The number of checkboxes added to p1 depend on the number of data values in the database table(t1) that satisfy a particular criteria.

be sure that current contents from JPanel is removed, then

p1.revalidate();
p1.repaint();
  • 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 :-)

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.

  • use CardLayout instead

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

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

Usually you call a validate() and then a repaint() when you want changes to the UI to actually be visible correctly.

Anupam Maiti

Try this link......This problem is already solved there....

Passing input from one frame to another(JAVA)

You should pass frame f1 to frame f2

JFrame Frame;
public f1(JFrame f){
    frame=f;
}

then, write a close method

int closeFrame(){
    f.fillPanel();
    f.show();
    return JFrame.HIDE_ON_CLOSE;
}

set default close operation of frame f2

public f1(JFrame f){
    frame=f;
    this.setDefaultCloseOperation(closeFrame());
}

Hope it's ok.

Well one thing you can do is in the ActionListener for button you can perform these operations:

//jp is a JPanel
//remove the current JPanel
frame.remove(jp);

//do the changes you want to do
//set sizes and border as before 
//again add the panel

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