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

  • Home
  • SEARCH
  • 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 8601197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:47:14+00:00 2026-06-12T01:47:14+00:00

I am making an interface with a JPanel inside a JFrame of which the

  • 0

I am making an interface with a JPanel inside a JFrame of which the width of the JPanel is set to be equal to the with of the JFrame. Contrary to my expectation though when I run the program to view the display, the JPanel displays as a very small box smaller than the required size which should have width equal to that of JFrame. However, when I reduce the width of the JPanel by about 6, it displays well it’s exact size in the JFrame. Seems to me that the JFrame could have some kind of margin or padding but I don’t know really. Please help and show why I cannot make the JPanel width same as that of the parent JFrame and also how it can be done if possible. I really want to have them same width cause that is how my design is set. My code is below:

`import java.awt.*; //importing awt package
import javax.swing.*; //importing swing package

//class definition
public class PMSysClient {

//declaration of variables
private JFrame lgFrame; //login frame
private JFrame fdFrame; //frame for front desk
private JFrame docFrame; //frame for doctor
private JPanel logHeadPan; //header panel in login
private JPanel logAreaPan; //login area panel

//constructor definition
public PMSysClient() {
    initialise();
}//end of constructor

//method to initialise class
public void initialise() {
    lgFrame = new JFrame();
    Container cont = lgFrame.getContentPane();
    lgFrame.setSize(863, 569);
    lgFrame.setLocationRelativeTo(null);
    lgFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    cont.setBackground(new Color(231, 228, 204));
    cont.setLayout(new GridBagLayout());

    logHeadPan = new JPanel();
    logHeadPan.setBackground(new Color(204, 153, 255));
    logHeadPan.setPreferredSize(new Dimension(863, 210));
    GridBagConstraints c1 = new GridBagConstraints();
    c1.weighty = 0.1;
    c1.weightx=0.1;
    c1.gridx = 0;
    c1.gridy = 0;
    c1.anchor = GridBagConstraints.FIRST_LINE_START;

    lgFrame.add(logHeadPan, c1);
    lgFrame.setVisible(true);
}//end of initialise

//main method definition
public static void main(String[] args) {
    try {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception e) {
    }
    new PMSysClient();
}//end of main method
}`
  • 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-12T01:47:15+00:00Added an answer on June 12, 2026 at 1:47 am

    Add the setMinimumSize() and keep setPreferredSize(). The sizes can be different. But you need to use both methods.

    logHeadPan.setMinimumSize(...)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I was working on a bit of fun, making an interface to run
I am making an application which is a user interface to access 2 types
I am making an application which will have an interface similar to Photoshop: multiple
I am creating a program that uses JFrame, JPanel, JLabel and all other sorts
I am making a user interface which shows graphs and manipulates graphs. The class
I am trying to set background image width 100, height 100 and making the
I'm making use of an interface for a set of classes. I have a
I'm making an interface to edit scenarios for a game. Basically it consists of
Ok I am making a simulated OS type interface. It should open up windows
I am having an issue in an interface I am making in Java. It

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.