Other Software > Developer's Corner
Simple Java Panel setLocation issue. help?
(1/1)
relequestual:
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 ---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); } }
Navigation
[0] Message Index
Go to full version