This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes panel.setSize() Not Working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "panel.setSize() Not Working" Watch "panel.setSize() Not Working" New topic
Author

panel.setSize() Not Working

chander shivdasani
Ranch Hand

Joined: Oct 09, 2007
Posts: 206

I have a Frame of Size 300 X 300. In this frame i have two panels, one of size 300 x 100 and other of 300 x 200. The first panel has a Button in the Center while the other panel has 9 buttons arranged in a Grid.

For doing this, i am creating a frame with size 300 x 300 and two panels, one with size 300 x 100 and other with 300 x 200. The problem is when i use panel.setSize(), it is not creating any effect. Below is the code that i have written.



Where am i going wrong?

Enjoy, Chander
SCJP 5, Oracle Certified PL/SQL Developer
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167
    
    8

GridLayout totally ignores the component's size.
From the API docs for GridLayout
The container is divided into equal-sized rectangles, and one component is placed in each rectangle


To fix your problem,
1) Change from GridLayout to FlowLayout
2) For the panels, use setPreferredSize() instead of setSize().

PS. In your code you haven't set the preferred size for the first panel.

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: panel.setSize() Not Working
 
Similar Threads
Linear Search Woes
what layouts to use
Converting an Application into JApplet
Frames
Calling the repaint() method