이름을 나타내는 텍스트 필드와 등록 유형의 콤보 박스가 있습니다. 그런 다음 옆에 확인란이 있지만 다른 두 필드 아래에 있어야합니다. 여기에 제가 코딩 한 내용이 있습니다 :Swing의 텍스트 입력란 아래에 내 체크 박스를 삽입하는 방법은 무엇입니까?
public RegPanel()
{
//create a new panel
new GridLayout(2,1);
//create one of two subpanels
subPanel = new JPanel(new FlowLayout());
//create a textfield
regTextField = new JTextField(20);
//create a combobox and don't let anyone add to it
regComboBox = new JComboBox(regOptions);
//create a border for the subpanel
subPanel.setBorder(BorderFactory.createTitledBorder("Registrant's Name & Type"));
//add regTypePanel and regBox to the panel
subPanel.add(regTextField);
subPanel.add(regComboBox);
//create a second subpanel with a flowlayout
subPanel2 = new JPanel(new FlowLayout());
//create a checkbox
regCheckBox = new JCheckBox("Dinner and Keynote Speech");
subPanel2.add(regCheckBox);
//add the subpanels to the main panel
add(subPanel);
add(subPanel2);
}
내가 누락 된 아이디어가 있습니까? 진절머리 나는 레이아웃에 대해 미안하다. 나는보기를 수정하는 방법을 알 수 없다.
그래서 GridLayout을 올바르게 설정하지 않았다는 것을 알았 기 때문에이를 "setLayout (new GridLayout (2,1));으로 변경했습니다. 이제 내 GUI에서 완전히 다른 모든 위치를 망쳤습니다. 당신이 setLayout(...)
에서 사용하지 않는 요소.