我试图在JOptionPane中格式化按钮的位置。现在他们并排,但我想把它们放在一起。
我尝试进行全局配置但是没有用。我怎么做到这一点?
Object[] options = { "Restart Game at Level 1",
"Restart and Increase Difficulty (Speed)",
"Change Game Map", "Exit Game" };
int n = JOptionPane.showOptionDialog(gamePanel,
"GAME OVER - YouHit a Wall and Died! ",
"Game Over!", JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE, null, options, options[3]);
答案 0 :(得分:0)
有一种方法,但我不推荐它,因为它假设了JOptionPane的内部实现。有两件事要做:
更改包含选项的内部组件的布局(其中 在位置1)
JOptionPane op = new JOptionPane("GAME OVER - YouHit a Wall and Died! ");
op.setOptions(options );
((Container)op.getComponent(1)).setLayout(new GridLayout(4, 1));
JDialog dlg = op.createDialog("Game Over!");
dlg.setVisible(true);