Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JCheckBox is not visible  RSS feed

 
Rj Rajat Jain
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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.
 
Fred Kleinschmidt
Bartender
Posts: 560
9
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Can't thank you enough sir. This thing just made my code alright. Thanks again!!
 
Campbell Ritchie
Marshal
Posts: 55741
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read more about grid layout here.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!