DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Simple Java Panel setLocation issue. help?  (Read 5,862 times)

relequestual

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 93
Simple Java Panel setLocation issue. help?
« on: February 16, 2009, 01:10 PM »
Im currently working on a project which has a game panel and a control panel.
The game panel works fine, however now im trying to create the control panel in the same frame, and i cant seem to set its location.
Its location is under the game panel, however I cant seem to make this stick, as the button always displays at the top of the screen in the middle.

I know with java you have little control over they layout, but surely I must be able to group a section of buttons and make sure they display in one area only?

Code pasted below in spoiler
Thanks in advance

Rel


Spoiler (click to show/hide)
Code: (java)
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JButton;
import javax.swing.JPanel;


@SuppressWarnings("serial")
public class hospitalControlPanel extends JPanel
{
	private JButton button1;
	public hospitalControlPanel()
	{
		button1 = new JButton("im a button");
		add(button1);
		setBackground(Color.lightGray);
		setLocation(0,810);
		Dimension CPanelDim = new Dimension(1025,90);
		setSize(CPanelDim);
		
		
		System.out.println(this.getLocation());
	}
}
Code: (java)
import java.awt.Dimension;
import java.awt.Point;

import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 * 
 */

/**
 * @author Rel
 *
 */
public class hospital
{

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		JFrame gameWindow = new JFrame("Java Hospital");
		gameWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		gameWindow.setPreferredSize(new Dimension(1025, 900));
		gameWindow.setResizable(false);	
		
		//gameWindow.getContentPane().add (new hospitalGamePanel());
		gameWindow.getContentPane().add(new hospitalControlPanel());
		
		gameWindow.pack();
		gameWindow.setVisible(true);
	}


}
<a href="http://feeds.feedburner.com/~r/Appaholic/~6/3"><img src="http://feeds.feedburner.com/Appaholic.3.gif" alt="Are You An AppAholic?" style="border:0"></a>

Original address: https://www.donationcoder.com/forum/index.php?topic=17053.0