我想知道如何将我的按钮定位到 JPanel 的中心。截至目前,该按钮位于我的“mms”(用作我的背景图像)的顶部,但位于面板的上边缘居中。如何将此按钮定位在图像的中心?
//MainMenu setup
JPanel card2 = new JPanel();
card2.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(2,2,2,2);
gbc.anchor = GridBagConstraints.CENTER;
MainMenuScreen mms = new MainMenuScreen();
card2.add(mms, gbc);
mms.add(menuButton1, gbc);