• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

add component to a visible component

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic