• 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

JCheckBox is not visible

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was doing Chapter No. 13, from O' Reilly's Head First Java, and was making up the "BeatBox App" as dubbed by the book. The program compiles fine, but the checkboxes are not visible. here is the code -



The output is -


I think I've added the checkboxes correctly, but I'm not so sure about the grid layout.
 
Bartender
Posts: 732
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are creating 256 checkboxes, all lined up side by side in a single row. There is not enough room on your screen to draw them - even if your screen is 1760 pixels wide, with your layout each button gets only about 4 pixels, so with the border there is no room to draw anything. Try it with 4 checkboxes and see what happens. then with 20, or 50

Why do you use

Make up your mind: the pack() call discards the result of the setBounds() and sets the size to the preferred size of all of the contents.

And why use a GridLayout without specifying the number of rows and columns?
 
Rj Rajat Jain
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Fred Kleinschmidt wrote:You are creating 256 checkboxes, all lined up side by side in a single row. There is not enough room on your screen to draw them - even if your screen is 1760 pixels wide, with your layout each button gets only about 4 pixels, so with the border there is no room to draw anything. Try it with 4 checkboxes and see what happens. then with 20, or 50

Why do you use

Make up your mind: the pack() call discards the result of the setBounds() and sets the size to the preferred size of all of the contents.

And why use a GridLayout without specifying the number of rows and columns?



Thank you fir the quick reply. GridLayout isn't actually taught in the book, so I copied it thinking it must be correct. I'll set the no. of columns and rows now, searching for it
 
Rj Rajat Jain
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can't thank you enough sir. This thing just made my code alright. Thanks again!!
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read more about grid layout here.
 
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic