Problems with GUI GridLayout and Panels in Frames

Posted on 2003-02-20
Medium Priority
Last Modified: 2008-02-01
I'm practicing Java by working on programming "Connect 4" the board game. Here's some info about the structure of it. The application object Connect4 extends Frame and uses the default FlowLayout. A Gameboard extends Panel, uses a GridLayout, and is a member of Connect4. The Gameboard has a Canvas object for each grid element, which is used to paint the gamepieces.

Problem: When the frame is resized the grid elements resize themselves as well.

Q: Is it possible to make the grid a fixed size, regardless of the size of the Frame? I would like to have the elements on the grid stay a constant size if possible, rather than grow and shrink with the Frame. Any suggestions?

Problem: I wanted to add a TextArea as a status window for the players onto the "Connect 4" Frame. I instantiated a Panel and TextArea then added it to the Frame.
    // Gameboard has been added to "this" Frame already
    ta = new TextArea( "Status", 2, 30 );
    p  = new Panel();
    p.add( ta );
    // add status panel to the "Connect4" Frame
    this.add( p );

This seems to coverup the Gameboard, instead of being placed next to, or below it in the Connect 4 Frame. I expected both the Status Panel and Gameboard Panel to be displayed.

Q. How come both the Gameboard Panel and the Status Panel are NOT displayed in the Frame? The only this showing is the Status Panel. Any suggestions?

Question by:fivesigmaevent
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

membersh earned 200 total points
ID: 7991972
> Is it possible to make the grid a fixed size, regardless of the size of ..

Take a Panel [boo], set layout to null, set Bounds of gridpanel to required size, add it to boo & add boo the Frame.

Default layout of Frame is not Flow, its Border.

This is the reason for both the Status Panel and Gameboard Panel not being displayed at same time. Either change the layout or add status panel to BorderLayout.SOUTH.


Author Comment

ID: 7994139
Thanks membersh. Your advice worked perfectly.

Author Comment

ID: 7994156
Hopefully I will be good enough to help answer others' questions!

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month15 days, 7 hours left to enroll

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question