Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

add component to a visible component

 
shanu shawn
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I want to add a component(subPanel) to a already visible component(mainJPanel).
Here is my piece of code


Problem is added subPanel is not visible
can anyone help me,
Thank You All.


 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Don't call validate(), call revalidate() and repaint()

2. I don't see that you add mainPanel to any visible GUI hierarchy. For better help, post a SSCCE *
* http://mindprod.com/jgloss/sscce.html
 
Rob Spoor
Sheriff
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:I don't see that you add mainPanel to any visible GUI hierarchy.

I think that is the problem here. You can validate, revalidate and repaint a component all you want but if it isn't put into a window (directly or indirectly) it will never be visible.

For better help, post a SSCCE *
* http://mindprod.com/jgloss/sscce.html

SSCCE will now automatically be a link to sscce.org. No need to add links yourself anymore
 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:
SSCCE will now automatically be a link to sscce.org. No need to add links yourself anymore

Thank you Rob.
 
shanu shawn
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a Main Frame(NewFrame withBorder layout),on Line Start contains a LeftPanel (testlp) (flow layout)contains a method dynamicadd(),this method add add a JPanel of size 150 X 180 to LeftPanel (testLp), on LineEnd contains a RightPanel(rp) ,rp contains a button when it is clicked it should call the dynamicadd() method of testlp ,
The Problem is added jpanel of size 150 X 180 is not visible on Leftpanel.
Here is my code for MainFrame


here is code for LeftPanel (testlp)


and here is the code for RightPanel (rp)



Please help me in this
Thank you all.
 
Maneesh Godbole
Saloon Keeper
Posts: 11070
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl already gave you the solution.
Darryl Burke wrote:1. Don't call validate(), call revalidate() and repaint()
 
shanu shawn
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for reply,
I used revalidate method in my code, but the added panel is not visible.
help me in this
Thnak you all.
 
Maneesh Godbole
Saloon Keeper
Posts: 11070
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really dont know how to make this simpler.
Darryl suggested you invoke revalidate() and repaint()
 
shanu shawn
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i add a JButton to left panel(testlp) (above code of testlp) ,and called a dynamicadd() method with in actionperformed of created JButton , dynamicadd() method is adding a jpanel of size 150 X 180 to leftpanel(testlp),
if i call the same method from jButton1ActionPerformed of right pane the a jpanel of size 150 X 180,is not adding to leftpane(testlp).
can any body tell me why it is behaving like that.
Thank you all.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic