Originally posted by vivek modi:
Hi Everybody !! I am new to Swing and am working on a GUI based Elevator Simulation System. I am using Frame on which I am trying to put a Panel. But the panel does not set to the size I want it to even if I use setSize() method. I am posting the code .Could anyone please help me.
Thanks !!
Originally posted by vivek modi:
I want to display the panel at my desired location and using method setLocation() it does not work.
Is there any other way ?
Maneesh Godbole wrote:
Originally posted by vivek modi:
I want to display the panel at my desired location and using method setLocation() it does not work.
Is there any other way ?
Why do you want to specify the exact location? Have you considered what will happen if the user resizes the frame or the user is running some different screen resolution? The LayoutManagers are designed to handle all these.
Even then, if your requirement dictates that you specify a location, this is what you need to do.
1) Set the layout of the content pane to null by calling getContentPane.setLayout(null);
2) Add the panel to the content pane.
3) Define the bounds of the panel by calling panel.setBounds(int x, int y, int width, int height) where x,y are the location and the width and height are the dimensions of the panel.
Please note the step#2 should be called before step#3 , else it wont work.
Best of luck.
[ November 19, 2007: Message edited by: Maneesh Godbole ]
Maneesh Godbole wrote:Please note the step#2 should be called before step#3 , else it wont work.
luck, db
There are no new questions, but there may be new answers.
Maneesh Godbole wrote:
Originally posted by vivek modi:
I want to display the panel at my desired location and using method setLocation() it does not work.
Is there any other way ?
Why do you want to specify the exact location? Have you considered what will happen if the user resizes the frame or the user is running some different screen resolution? The LayoutManagers are designed to handle all these.
Even then, if your requirement dictates that you specify a location, this is what you need to do.
1) Set the layout of the content pane to null by calling getContentPane.setLayout(null);
2) Add the panel to the content pane.
3) Define the bounds of the panel by calling panel.setBounds(int x, int y, int width, int height) where x,y are the location and the width and height are the dimensions of the panel.
Please note the step#2 should be called before step#3 , else it wont work.
Best of luck.
[ November 19, 2007: Message edited by: Maneesh Godbole ]
pratik maru wrote:how make my swing application program work in different resolution systems
luck, db
There are no new questions, but there may be new answers.
Darryl Burke wrote:
pratik maru wrote:how make my swing application program work in different resolution systems
Use an appropriate layout manager or combination of nested layouts and pack() the window that displays the GUI.
by appropriate layout manager you mean which one
can you give me an example
Consider Paul's rocket mass heater. |