Reputation: 15
Here I have a JPanel
with JLabels
and JTextfields
and some JButtons
. Where one JTextfield
is to get data from user and on clicking search button, it should get the relevant data from the database and display the result in the same panel. When I click submit button. I find no change in my screen, but when I resize the frame I can see the updated panel behind the previous one. Even I try remove(rp)
and then add it results the same as above.
How to replace a JPanel with the same with updated contents?
P.S: I want to remove and add the same panel with updated contents
my code looks like this while replacing
private void rp_validate(){
f.add(rp);
f.revalidate();
f.repaint();
f.pack();
}
Upvotes: 0
Views: 131
Reputation: 285430
setText(...)
passing information held in the setter method parameter to update the text displayed in your JPanel. Simple as pie.Fore example:
public void setMyData(MyData myData) {
this.myData = myData;
lastNameTextField.setText(myData.getLastName());
firstNameTextField.setText(myData.getFirstName());
addressTextfield.setText(myData.getAddress());
cityTextfield.setText(myData.getCity());
stateTextfield.setText(myData.getState());
// ... etc
}
Upvotes: 1