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
}`