Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8998467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:02:07+00:00 2026-06-16T00:02:07+00:00

I am writing a simple game withing which I am using a JFrame which

  • 0

I am writing a simple game withing which I am using a JFrame which contains a grid and a JPanel.
Here is my pseudo code:

void MyJframeConstructor()
{
  // some basic bootstrap logic
  // calling repaint to draw grid
  repaint();

  // Grid is drawn fine.
  // Showing user a confirm dialog box on which I add below JPanel.

  if(confirmed)
  {
   // GameInfoPanel extends JPanel.
    infoPanel = new GameInfoPanel(new FlowLayout(FlowLayout.LEFT));
    infoPanel.setPreferredSize(new Dimension(400, 100));
    infoPanel.setLocation(500, 50);
    this.add(infoPanel);
    infoPanel.validate();      
  }
}

My problem here is my JFrame or window is 480 x 680.
Within this I am drawing a grid in 480 x 480 area.
Below which I want the JPanel to be located at 500,50 with dimension 400, 100.
However, when I run this code, once the user confirms with OK, the JPanel fills up the entire JFrame.
How can I keep the panel in its location and consistent in size through out the life of the app ?
Any help is highly appreciated and thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:02:08+00:00Added an answer on June 16, 2026 at 12:02 am

    Within this I am drawing a grid in 480 x 480 area.

    • override PreferredSize for JPanel

    • then call JFrame.pack() and JFrame.setVisible(true) as last code lines

    • have to read InitialThread

    • if is there only one JPanel (JPanel filling entire JFrame) then to use built_in BorderLayout in JFrame f.e. myFrame.add(infoPanel, BorderLayout.CENTER) not FlowLayout

    • don’t to extend JFrame create this Object as local variable

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a Facebook application that is a simple board game which I
While writing a simple game using SBCL, CL-OPENGL, and Lispbuilder-SDL, I can across a
I am writing a simple game using Box2d-Jquery. By default the position of the
I am currently writing a simple snake clone game for Windows 8 using MonoGame.
I am writing a simple game in java using Ovals and the Graphics objects.
I'm currently writing a node.js app which is a simple Snake/Tron style game, however
I've been recently writing simple game in C++ with SFML. Here's my question: In
I'm currently writing a very simple game using python and pygame. It has stuff
I'm writing simple game with cells which can be in two states Free and
I'm writing a simple Java 2D game, displaying a grid. The grid is (for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.