This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes add component to a visible component Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "add component to a visible component " Watch "add component to a visible component " New topic
Author

add component to a visible component

shanu shawn
Greenhorn

Joined: Mar 29, 2010
Posts: 6
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

Joined: May 03, 2008
Posts: 4523
    
    5

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


luck, db
There are no new questions, but there may be new answers.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

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

Joined: Mar 29, 2010
Posts: 6
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

Joined: Jul 26, 2007
Posts: 10170
    
    8

Darryl already gave you the solution.
Darryl Burke wrote:1. Don't call validate(), call revalidate() and repaint()


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
shanu shawn
Greenhorn

Joined: Mar 29, 2010
Posts: 6
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

Joined: Jul 26, 2007
Posts: 10170
    
    8

I really dont know how to make this simpler.
Darryl suggested you invoke revalidate() and repaint()
shanu shawn
Greenhorn

Joined: Mar 29, 2010
Posts: 6
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: add component to a visible component
 
Similar Threads
Liquid LayoutManager
container's containment
trying to center buttons with fixed sizes
Aligning component from Right to Left
sharing a static jpanel