Problem updating java swing

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

However, JPanel does not β€œupdate” correctly after I call setText()on one of its labels. After processing and setting JPanel to visible (and I confirmed that there is correct data, etc.), JPanel is still in its initialized form.

In other words, what do I need to make the call setText()in JPanel inside the frame refresh the panel?

Basically I am wondering: if you update the label text inside the swing component that is nested inside the JFrame, should the update be visible? What needs to be done to update if not?

+3
source share
5 answers

Try the following:

myPanel.invalidate()

If this does not work, try sending the code.

+2
source

why do you even create JPanel ahead of time? why not create it again, with the right text, for the first time?

and every time you change the shortcut, you may need to re-check the panel; those.:

myPanel.validate()

What is this additional panel for? perhaps you should use a dialog; or just adding a JPanel to an existing frame.

+2
source

. , - , ( ). , , , , , , .

, , , - - - :

JLabels JPanel, setBounds(), x, y, height width. setBounds() , JPanel. , height, width ( getMinimumHeight() .., , ). , , 0. , , setText(), , , 0 ( , !).

... setBounds() , setText() ( ).

+2

. , .

- JInternalFrame? , , . , .

, , setText(), , JPanel?

+1

To make changes to your objects in memory fully and correctly applied to the graphical interface, you need to call the validate () and repaint () methods of the corresponding objects. validate () pretends to be a commit operation for recent changes. That way, if you change the label text, you won’t be able to see the change, even if you call repaint ().

0
source

Source: https://habr.com/ru/post/1753601/


All Articles