• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

panel.setSize() Not Working

 
Ranch Hand
Posts: 206
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic