窗口底部的JButtons截止



我一直在学习如何用Java制作GUI,作为作业的一部分,我们需要有两排按钮,一排在另一排之上。我有所有的按钮,但底部的按钮大约被切断了一半。我不知道如何让它们完全显示。我尝试调整窗口的 Y 大小,但它们仍然保持截断状态。有没有人知道如何让底部的三个按钮完全显示?正在发生的事情的图像

相关代码

JPanel rightA = new JPanel();
JPanel bottomB = new JPanel();
JPanel bottomB2 = new JPanel();
JLabel jlName = new JLabel("Item Name: ");
JLabel jlNum = new JLabel("Number of: ");
JLabel jlCost = new JLabel("Cost: ");
JLabel jlOwed = new JLabel("Amount Owed: ");
JButton jbCalculate = new JButton("Calculate");
JButton jbSave = new JButton("Save");
JButton jbClear = new JButton("Clear");
JButton jbExit = new JButton("Exit");
JButton jbLoad = new JButton("Load");
JButton jbPrev = new JButton("<Prev");
JButton jbNext = new JButton("Next>");
this.setTitle("Items Order Calculator");
this.setMinimumSize(new Dimension(400, 200));
rightA.add(jlName);
rightA.add(jtfName);
rightA.add(jlNum);
rightA.add(jtfNum);
rightA.add(jlCost);
rightA.add(jtfCost);
rightA.add(jlOwed);
rightA.add(jtfOwed);
bottomB.add(jbCalculate);
bottomB.add(jbSave);
bottomB.add(jbClear);
bottomB.add(jbExit);
bottomB2.add(jbLoad);
bottomB2.add(jbPrev);
bottomB2.add(jbNext);
jtfOwed.setEnabled(false);
rightA.setLayout(new GridLayout(4, 2));
this.add(rightA, BorderLayout.EAST);
bottomB.add(bottomB2);
this.add(bottomB, BorderLayout.SOUTH);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setVisible(true);

我认为问题是您将 bottomB2 面板添加到 bottomB 面板中,并且它们没有正确传达其首选大小。

尝试创建另一个具有边框布局的面板,并将它们添加到此面板的北部和南部区域。然后将这个新的底板添加到南部的 gui 中。

JPanel bottomAll = new JPanel(new BorderLayout());
bottomAll.add(bottomB, BorderLayout.NORTH);
bottomAll.add(bottomB2, BorderLayout.SOUTH);
this.add(bottomAll, BorderLayout.SOUTH);

最新更新