HELP.. I have a frame set to the screen size of my monitor, background color is yellow. I have a panel returned by midFrame() (outerPanel) supposed to be located at the center of my frame. i used the setBounds() to place my panel in the center but it doesn't do so.. and i have an inner panel with 2 more panels (a header and view panel) in it. the view panel is where i used the JLayeredPane so i could put components on top of each other-- a background image(using JLabel) and another panel(with buttons and more components). but i don't seem to add the components in the JLayeredPane correctly. what's wrong with my code? i hope you could help me.. parts of my code is included..

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class Frame extends JFrame {

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = new Dimension(640,600);   

    public Frame() {
        JPanel mainPanel = new JPanel();
        mainPanel.setBackground(new Color(255,255,158)); //pale yellow


        //frame attributes

    //middle frame
    public JPanel midFrame() {

        JPanel outerPanel = new JPanel();
        outerPanel.setBackground(new Color(129,220,254)); //pale blue

        //centers middle frame
        Point origin = new Point(0,0);

        if (frameSize.height > screenSize.height)
            frameSize.height = screenSize.height;
                     if (frameSize.width > screenSize.width)
            frameSize.width = screenSize.width;

                    origin.x = (screenSize.width - frameSize.width) / 2;
                    origin.y = (screenSize.height - frameSize.height) / 2;
                    [B]outerPanel.setBounds(origin.x, origin.y, 640,600);[/B]       
        //create inner panel
        JPanel innerPanel = new JPanel(new BorderLayout());
        JPanel headerPanel = new JPanel();
        JLayeredPane viewPanel = new JLayeredPane();

        JLabel headerlbl = new JLabel(new ImageIcon("../bg/header.png"));
        JLabel viewlbl = new JLabel(new ImageIcon("../bg/bg_view.png"));


        headerPanel.setBackground(new Color(128,255,128)); //light green
        viewPanel.setBackground(new Color(128,255,128));
        [B]viewPanel.add(viewlbl, new Integer(0));               //this doen't seem to work 
        viewPanel.add(shapePanel(), new Intger(1));[/B]

        innerPanel.add(headerPanel, BorderLayout.NORTH);
        innerPanel.add(viewPanel, BorderLayout.CENTER);
        [B]innerPanel.setBounds((origin.x+20), (origin.y+20), 600,500); [/B]    
        return outerPanel;
  ......... more codes ...........

    public static void main(String[] args) {
        new Frame();


hi guys, there is no reply yet to my problem.. is there anything you could suggest me to position my panel inside the frame? i tried using the setLocation() but still it's not working. Is there another way that i could use a JLayeredPane inside a JPanel? any suggestion would be abig help.. thanks!

This article has been dead for over six months. Start a new discussion instead.