944,051 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 6423
  • Java RSS
Sep 24th, 2004
0

Working with JLayeredPane and positioning of components.. HELP!

Expand Post »
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;
outerPanel.setBounds(origin.x, origin.y, 640,600);
//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);
viewPanel.add(viewlbl, new Integer(0)); //this doen't seem to work
viewPanel.add(shapePanel(), new Intger(1));


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


public static void main(String[] args) {
System.out.println("Frame.java");
new Frame();
}


}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
perky_jing is offline Offline
4 posts
since Sep 2004
Sep 26th, 2004
0

Re: Working with JLayeredPane and positioning of components.. HELP!

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!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
perky_jing is offline Offline
4 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: java programming
Next Thread in Java Forum Timeline: reading a file into code





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC