topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 7:25 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Simple Java Panel setLocation issue. help?  (Read 4605 times)

relequestual

  • Honorary Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 93
    • View Profile
    • AppAholic
    • Donate to Member
Simple Java Panel setLocation issue. help?
« on: February 16, 2009, 07:10 AM »
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
Code: Java [Select]
  1. import java.awt.Color;
  2. import java.awt.Dimension;
  3. import java.awt.Graphics;
  4.  
  5. import javax.swing.JButton;
  6. import javax.swing.JPanel;
  7.  
  8.  
  9. @SuppressWarnings("serial")
  10. public class hospitalControlPanel extends JPanel
  11. {
  12.         private JButton button1;
  13.         public hospitalControlPanel()
  14.         {
  15.                 button1 = new JButton("im a button");
  16.                 add(button1);
  17.                 setBackground(Color.lightGray);
  18.                 setLocation(0,810);
  19.                 Dimension CPanelDim = new Dimension(1025,90);
  20.                 setSize(CPanelDim);
  21.                
  22.                
  23.                 System.out.println(this.getLocation());
  24.         }
  25. }
Code: Java [Select]
  1. import java.awt.Dimension;
  2. import java.awt.Point;
  3.  
  4. import javax.swing.JFrame;
  5. import javax.swing.JPanel;
  6.  
  7. /**
  8.  *
  9.  */
  10.  
  11. /**
  12.  * @author Rel
  13.  *
  14.  */
  15. public class hospital
  16. {
  17.  
  18.         /**
  19.          * @param args
  20.          */
  21.         public static void main(String[] args)
  22.         {
  23.                 JFrame gameWindow = new JFrame("Java Hospital");
  24.                 gameWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  25.                 gameWindow.setPreferredSize(new Dimension(1025, 900));
  26.                 gameWindow.setResizable(false);
  27.                
  28.                 //gameWindow.getContentPane().add (new hospitalGamePanel());
  29.                 gameWindow.getContentPane().add(new hospitalControlPanel());
  30.                
  31.                 gameWindow.pack();
  32.                 gameWindow.setVisible(true);
  33.         }
  34.  
  35.  
  36. }

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