我正在尝试使用单选按钮制作一个简单的 GUI,并将它们分组到一个面板中。我希望它位于最左侧,所以我使用了 setBounds 方法。无论我在参数上输入什么数字,面板都不会移动。面板不受 setBounds 方法的影响吗?或者有另一种方法来定位我的面板。这是我的代码片段:
JPanel radioPanel = new JPanel();
radioPanel.setLayout(new GridLayout(3,1));
JRadioButton Rbutton1 = new JRadioButton("Credit Card");
JRadioButton Rbutton2 = new JRadioButton("E-Funds");
JRadioButton Rbutton3 = new JRadioButton("Check");
Rbutton3.setSelected(true);
ButtonGroup Bgroup = new ButtonGroup();
Bgroup.add(Rbutton1);
Bgroup.add(Rbutton2);
Bgroup.add(Rbutton3);
radioPanel.add(Rbutton1);
radioPanel.add(Rbutton2);
radioPanel.add(Rbutton3);
radioPanel.setBounds(10,50,50,40); //this is where I'm trying to position the panel with the radio buttons
paymentPanel.add(radioPanel);
contentPane.add(paymentPanel); //contentPane is the frame
contentPane.setVisible(true);