JPanel 6 JButton に、1 行に 3 つの JButton があり、別の 3 つの JButton の下にあるようにしようとしています。JPanel が Flow Layout Manager で明示的に動作することを知っているので、次のようなアイデアを思いつきました。
JFrame frame = new JFrame();
JPanel panel = new JPanel();
frame.getContentPane().add(panel);
JButton button1 = new JButton();
JButton button2 = new JButton();
JButton button3 = new JButton();
JButton button4 = new JButton();
JButton button5 = new JButton();
JButton button6 = new JButton();
button1.setSize((panel.WIDTH)/3,(panel.HEIGHT)/2);
button2.setSize((panel.WIDTH)/3,(panel.HEIGHT)/2);
button3.setSize((panel.WIDTH)/3,(panel.HEIGHT)/2);
button4.setSize((panel.WIDTH)/3,(panel.HEIGHT)/2);
button5.setSize((panel.WIDTH)/3,(panel.HEIGHT)/2);
button6.setSize((panel.WIDTH)/3,(panel.HEIGHT)/2);
panel.add(button1);
panel.add(button2);
panel.add(button3);
panel.add(button4);
panel.add(button5);
panel.add(button6);
残念ながら、これは機能しません。ボタンのサイズを変更することはできません。誰かアイデアがありますか?どうもありがとう。