Solved

Java Swing: Components don't show up

Posted on 2011-09-21
10
262 Views
Last Modified: 2012-05-12
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
Comment
Question by:dshrenik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 41

Accepted Solution

by:
HonorGod earned 125 total points
ID: 36576048
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
 
LVL 47

Expert Comment

by:for_yan
ID: 36576054
Maybe you want to paste your code.
It is very common to add one JPanel to another JPanel - should not have any problems
0
 

Author Comment

by:dshrenik
ID: 36576086
Unfortunately, I'm not allowed to paste code. Sorry about that!
Can you tell me some possible things that could be going wrong?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 47

Expert Comment

by:for_yan
ID: 36576105

I think HonorGod has a good point - are you indedadding the second ;panel after you show the window?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36576116
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
 

Author Comment

by:dshrenik
ID: 36576127
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
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 125 total points
ID: 36576218
If you're adding it dynamically, for parent JPanel 'p' do
p.validate();
p.repaint();

Open in new window

0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 125 total points
ID: 36576259

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
 
LVL 10

Assisted Solution

by:gordon_vt02
gordon_vt02 earned 125 total points
ID: 36580582
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
 
LVL 41

Expert Comment

by:HonorGod
ID: 36710057
Thanks for the grade & points.

Good luck & have a great day.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Certificat to iSeries KeyStore 1 31
hibernate example using maven 12 111
How to configure empty element in XML Document parser? 15 58
Html Table Looping (part 2) 5 42
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question