• 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

Simple GUI program: changing color of a panel.

 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Need your help to sort out the below problem.

This is a beginner GUI program - Changing the color of a panel when a button is clicked. This button is in the top panel and the color panel is the bottom one.



This program might look bit lengthly and messed up. My apologies!

This program is compiled within Netbeans but does't show the bottom panel when run.


 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since it does not have any child components, it's preferred size is 0x0. BorderLayout does maintain the preferred height for the NORTH and SOUTH components, and the preferred width for the WEST and EAST components. The CENTER component gets what's left. So your frame has a panel the size of the button at the top, a panel with height 0 at the bottom, and nothing in the center.

Either give the panel a preferred size, or add it using BorderLayout.CENTER.
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow! that was a quick reply! Thanks Rob.

I hadn't thought about BorderLayout.CENTER but i had tried panel.setSize(200, 200) with BorderLayout.SOUTH and it didn't work!
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's because almost all layout managers completely ignore any size you give it using setSize. Only the minimum, preferred and maximum sizes are sometimes respected.
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic