• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • 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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

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