• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

Java Swing: Components don't show up

I am adding a JPanel to another JPanel. The problem is that the inner JPanel does not show up until I click at the location where it is supposed to appear.

Please let me know what I could be missing. Thanks!
0
dshrenik
Asked:
dshrenik
  • 4
  • 2
  • 2
  • +2
4 Solutions
 
HonorGodCommented:
Are you adding the second JPanel after the container has been painted?

Consider calling the frame.repaint() method

http://download.oracle.com/javase/7/docs/api/javax/swing/JFrame.html#repaint(long, int, int, int, int)
0
 
for_yanCommented:
Maybe you want to paste your code.
It is very common to add one JPanel to another JPanel - should not have any problems
0
 
dshrenikAuthor Commented:
Unfortunately, I'm not allowed to paste code. Sorry about that!
Can you tell me some possible things that could be going wrong?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
for_yanCommented:

I think HonorGod has a good point - are you indedadding the second ;panel after you show the window?
0
 
for_yanCommented:
In general, unless there is some specvial need - just create all GUI first and then show
the window when all elements are already created and are in place, then say
setVisible(true);
0
 
dshrenikAuthor Commented:
I am not sure. Sorry if question sounds silly - I am new to Swing:
What is the frame here, and how do I get a reference to it?
Do I just say this.repaint()? (where this is a jpanel)?
0
 
CEHJCommented:
If you're adding it dynamically, for parent JPanel 'p' do
p.validate();
p.repaint();

Open in new window

0
 
for_yanCommented:

If you say this.setVisioble(true) when you shoow it, then you should say this.repaint() after you add a new panel

If you say frame.setVisible(true); then you should asy frame.repaint();

Better don't setVisible() before you add everything to your GUI
0
 
gordon_vt02Commented:
What Layout are you using?  I've seen that happen before where multiple components are added to a Layout in the same location -- or when you don't specify a location properly for the Layout.
0
 
HonorGodCommented:
Thanks for the grade & points.

Good luck & have a great day.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now