我的应用程序处于全屏独占模式,我希望 JPanel 主面板位于 LAST_LINE_START 中,并在左右两侧进行一些填充。但是当我运行这个程序时,它只在屏幕中央显示主面板。我也尝试了其他位置,但它们也不起作用。
private void mainWindow()
{
gls =(JPanel) mainUi.getGlassPane();
gls.setLayout(new GridBagLayout());
JPanel mainPanel = new JPanel(new GridLayout(4,1));
nwGame = new JButton("New Game");
nwGame.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
gls.setVisible(false);
startGame(0);
mainUi.repaint();
}
});
ldGame = new JButton("Load Game");
ldGame.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
}
});
changeProfile = new JButton("Change Profile");
changeProfile.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
}
});
qtGame = new JButton("Quit Game");
qtGame.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
}
});
GridBagConstraints gbc = new GridBagConstraints();
gbc.ipadx = 10;
gbc.ipady = 10;
gbc.anchor = GridBagConstraints.LAST_LINE_START;
mainPanel.add(nwGame);
mainPanel.add(ldGame);
mainPanel.add(changeProfile);
mainPanel.add(qtGame);
gls.add(mainPanel,gbc);
gls.setVisible(true);
mainUi.add(gls);
if(!mainUi.isVisible())
mainUi.setVisible(true);
}