Reputation: 309
So I have a panel and depending upon users entry they are populated with an x number of jlabels. Now the problem is, when the user entered information the labels successfully populate but they do not display properly in the panel; they don't even show.
Only when I resize the frame they appear?
Upvotes: 1
Views: 102
Reputation: 1419
invalidate
marks a component as needing to be relaid out soon because the component or one of its children has been resized or become visible or invisible. invalidate
is called on a component automatically when children components are added/removed.
validate
checks that a container is valid and if not, calls doLayout or invalidateTree to calculate positions and sizes of children components. validate
effectively redoes the layouts if necessary, deciding on new sizes and locations of all components in the container.
After adding/removing components from a container, validate
must be called on the parent to let the LayoutManager redo the layout. Calling validate
does not schedule a repaint, so you may need to call repaint
after the validate
.
Upvotes: 0
Reputation: 1218
usually you have to call:
JPanel yourPanel = new JPanel();
yourPanel.repaint();
yourPanel.validate();
Upvotes: 1
Reputation: 30445
It's been a while since I did Swing programming and I am trying to remember the method which you are supposed on a container after you add components. I think it's revalidate()
.
Upvotes: 1