2 つの JPanel を含む非常に単純なフレームの使用に問題がありました。問題は、4 つの JButton を含む Center JPanel のレイアウトにあります。ボタンまたは GridLayout を使用する JPanel に直接、より適切なサイズを設定するにはどうすればよいですか。写真の問題:
alt http://img42.imageshack.us/img42/4601/horrible.jpg !
コードは次のとおりです。
JTextField textField = new JTextField("");
textField.setPreferredSize(new Dimension(200,20));
JPanel textPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
textPanel.add(textField);
window.add(textPanel, BorderLayout.NORTH);
JButton plus = new JButton("+");
//plus.setPreferredSize(new Dimension(50,50)); nothing would change
JButton minus = new JButton("-");
JButton per = new JButton("x");
JButton divide = new JButton("/");
JPanel prova = new JPanel(new GridLayout(2,2,10,10));
Dimension d = new Dimension(20,20);
prova.setMaximumSize(d); // nothing changed!
prova.add(plus);
prova.add(minus);
prova.add(per);
prova.add(divide);
window.add(prova, BorderLayout.CENTER);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setSize(250,300);
window.setResizable(false);
window.setVisible(true);`
良い解決策はどれですか?
敬具