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 {

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

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

        mainPanel.add(midFrame());
        getContentPane().add(mainPanel);

        //frame attributes
                     setTitle("PicPuzz");
        setSize(screenSize);
        setUndecorated(true);
        show();                 
    }

    //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"));

        viewPanel.setOpaque(true);

        headerPanel.setBackground(new Color(128,255,128)); //light green
        viewPanel.setBackground(new Color(128,255,128));
        headerPanel.add(headerlbl);
        [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]    
        outerPanel.add(innerPanel); 
        return outerPanel;
    }
  ......... more codes ...........


    public static void main(String[] args) {
        System.out.println("Frame.java");
        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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.