Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Add jlabel dynamically in a jpanel (revalidate didn't work) [SOLVED]  RSS feed

 
Rihab Kallel
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a method that tries to add labels dynamically in JPanel in the PackingByVolDialog class:



and in an other class , I call the `addContent` method as follows:






even when using `repaint` and `revalidate` of the JPanel, only the last output is displayed in the window.

Does anyone know where the problem is?
 
Campbell Ritchie
Sheriff
Posts: 53749
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you displaying those panels? Are they in the same location or different locations?
You appear to be overwriting the panel which is the content pane every time you go through the loop, so the older versions disappear.
 
Fred Kleinschmidt
Bartender
Posts: 507
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you calling contentPanel.revalidate() and contentPanel.repaint() ? Especially before you add contentPanel to a parent!
What is "dialog" ? What is its layout manager? It is likely, as Campbell Ritchie pointed out, that you are replacing the old one each time you add the new one.
And if you do add them correctly, you will need to call revalidate on dialog (you need to revalidate the container that gets new items, not the new items themselves).
 
Rihab Kallel
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have already fixed the problem, thank you
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!