• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JPanel not displaying in pop up window(jFrame)

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope. I just posted an simple example of such a thing here.
Show us some code.
 
Matt Wilcko
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I meant "dont see any of the window" above..
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic