File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JPanel not displaying in pop up window(jFrame) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JPanel not displaying in pop up window(jFrame)" Watch "JPanel not displaying in pop up window(jFrame)" New topic
Author

JPanel not displaying in pop up window(jFrame)

Matt Wilcko
Ranch Hand

Joined: Sep 23, 2003
Posts: 65
Hi,
From my desktop applications main window(jframe) I open a new window(jframe). I have gotten the contentpane for the new window and added a jpanel to it(which has a jLabel). The new window appears just fine but thats it.. the contents I have added(jLabels) do not appear.. just an empty gray area.. Do you have to do something different with JFrame's when they are a new window from you app's main window?
Thanks,
Matt
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8710
    
    6

Nope. I just posted an simple example of such a thing here.
Show us some code.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Matt Wilcko
Ranch Hand

Joined: Sep 23, 2003
Posts: 65
Hi.. the code is below.. I've tried with and without setting a layout manager with no luck.. its probably something simple:

package AdMakerApp;
import java.awt.Container;
import javax.swing.*;
import java.awt.*;
public class OneMomentFrame extends JFrame{

Container contentPane;

public OneMomentFrame(){

setTitle("One Moment Please...");

setBounds(AdMakerApp.screenSize.width/2, AdMakerApp.screenSize.height/2, 300, 300);

contentPane = getContentPane();

contentPane.setLayout(new BorderLayout());
JPanel oneMomentPanel = new JPanel();
JLabel oneMomentLabel = new JLabel("One Moment Please...");
oneMomentPanel.add(oneMomentLabel);
contentPane.add(oneMomentPanel, BorderLayout.NORTH);
}
}

**** Im calling the new window with OneMomentFrame oneMoment = new OneMomentFrame(); and then oneMoment.setVisible(true);. The window appears okay, my JLabel simply isn' there. Thanks in advance!
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
Make a call to "pack();" as the last thing in your constructor. This gives the layout manager a change to arrange (size and place) the components it is managing.
Matt Wilcko
Ranch Hand

Joined: Sep 23, 2003
Posts: 65
Hi,
I tried using pack() but all that seems to happen is that you do see any of the window, just the title bar which makes me wonder if the JPanel is not getting added to the jframe somehow.
Thanks.
Matt Wilcko
Ranch Hand

Joined: Sep 23, 2003
Posts: 65
I meant "dont see any of the window" above..
Jason Steele
Ranch Hand

Joined: Apr 25, 2003
Posts: 100
JFrame's default Layout is BorderLayout.
If you want the BorderLayout to remain, do not call contentPane.setLayout(new BorderLayout());
just add the component like:

also, try moving the setBounds call to the end.


An egg is a chicken's house!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPanel not displaying in pop up window(jFrame)
 
Similar Threads
JPanels and JInternalFrames
Resizing Widgets in Frame
Making JTabbed Pane visible???
Communicate between JFrames
Problem repainting overlapping JPanels