大家好,我是Java编程ID的初学者,喜欢在这里问一些有经验的编码员。因此我尝试制作一个库存系统,但是布局Image Link出现问题。“年度余额”面板必须在“销售记录”面板下方,然后“销售记录”面板必须填充该空间水平上方。任何人都有什么问题的想法。
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();
}
答案 0 :(得分:1)
您尚未为这些约束指定gridx
/ gridy
。它们默认为RELATIVE
,因此下一个分量在水平和垂直方向上都将移动。
(如果我最想更改您的代码的一件事,那就是命名。我不在乎类型(使用名称),因此请删除该类型,并且不要缩写其余有用的词。同样值得注意的是GridBagConstraints
数据已被复制,因此您可以在适当的地方重用它们。)