Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java swing update problem

Tags:

java

swing

I have a Frame class (extends JInternalFrame). Inside the class I am instantiating a JPanel and initializing setVisisble(false). After the user clicks a buttom in the frame and does some processing, I call a method inside of the JPanel to update one of its labels. I then do setVisible(true) on the JPanel.

However, the JPanel is not "refreshing" correctly after I call setText() on one of its labels. After the processing and setting the JPanel to visible (and I confirmed that the right data is there etc), the JPanel still is in its initialized form.

In other words, what do I need to do so that calling setText() on a JPanel within a frame actually refreshes the Panel?

Basically i'm wondering: if you update the text of a label inside a swing component which is nested inside of a JFrame, should the update be visible? What needs to be done to refresh if not?

like image 531
aeq Avatar asked May 03 '26 01:05

aeq


1 Answers

Try this:

myPanel.invalidate()

If that doesn't work, then maybe try posting some code.

like image 119
riwalk Avatar answered May 05 '26 16:05

riwalk