Gridbaglayout problem with layout (java swing)

SeQuoia :

Good day everyone, as I'm a beginner with java programming id like to ask some experienced coders here. so I am trying to make an inventory system but there is a problem with my layout Image Link The "Annual balance" panel must be below the "Record of sales" panel then the "Record of sales" panel must fill the space above horizontally. Anyone have an idea on what is the problem.

public MainViewForm(String text)
{



       setTitle("Computer Warehouse ni SeQuoia");  
       setLayout(new GridBagLayout());
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
       setSize(1200,900);        
       setResizable(true);
       setVisible(true);



       mBar = new JMenuBar();
        setJMenuBar(mBar);

       mFile = new JMenu("FILE");
    mBar.add(mFile);

    mEdit = new JMenu("EDIT");
    mBar.add(mEdit);

    mView = new JMenu("VIEW");
    mBar.add(mView);

    mSave = new JMenu("SAVE");
    mBar.add(mSave);

    tBSave = new JToggleButton("SAVE");
    mSave.add(tBSave);

    mHelp = new JMenu("HELP");
    mBar.add(mHelp);

     mOption = new JMenu("OPTION");
     mBar.add(mOption);

     mEnd = new JMenu("END");
     mBar.add(mEnd);

     tbExit = new JToggleButton("EXIT");
     mEnd.add(tbExit);


   dlyForm = new DailyForm();
   mtlyForm = new MonthlyForm();
   tForm = new TableForm();
   abForm = new AnnualBalanceForm();

   GridBagConstraints gbc_dlyForm = new GridBagConstraints();
   gbc_dlyForm.anchor=GridBagConstraints.FIRST_LINE_START;
   gbc_dlyForm.weightx=1;
   gbc_dlyForm.weighty=1;
   gbc_dlyForm.gridx=0;
   gbc_dlyForm.gridy=0;
   add(dlyForm,gbc_dlyForm );

   GridBagConstraints gbc_mtlyForm = new GridBagConstraints();
   gbc_mtlyForm.weightx=1;
   gbc_mtlyForm.weighty=1;
   gbc_mtlyForm.gridx=0;
   gbc_mtlyForm.gridy=0;
   gbc_mtlyForm.insets=new Insets(225,0,0,0);
   gbc_mtlyForm.anchor=GridBagConstraints.LINE_START;
   add(mtlyForm,gbc_mtlyForm);

   GridBagConstraints gbc_tForm = new GridBagConstraints();
   gbc_tForm.fill=GridBagConstraints.HORIZONTAL;
   gbc_tForm.weightx=0.1;
   gbc_tForm.weighty=0.1;
   gbc_tForm.anchor= GridBagConstraints.CENTER;
   add(tForm,gbc_tForm);

   GridBagConstraints gbc_abForm = new GridBagConstraints();
   gbc_abForm.anchor= GridBagConstraints.PAGE_END;
   gbc_abForm.weightx=1;
   gbc_abForm.weighty=1;

   add(abForm,gbc_abForm);

   pack();
}
Tom Hawtin - tackline :

You've not specified gridx/gridy for those constraints. They default to RELATIVE, so the next component moves over on both the horizontal and vertical.

(If there's one thing I'd most like to change about your code, it's the naming. I don't care about the type (in the name), so remove that and don't abbreviate the remaining useful words. Also worth noting the the GridBagConstraints data gets copied, so you can reuse them where appropriate.)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=107627&siteId=1