我找不到错误来挽救我的生命。错误是“约束必须是字符串(或空)”我不知道为什么它会给我这个错误,我必须错过一些简单的东西。
我尝试添加
例如: dataPane = new JPanel(new GridBagLayout());到我所有的面板,什么也没有。
我正在尝试将面板 (2) 添加到扩展面板。
这是我的代码:
public class SearchFlight extends JPanel {
//giving names to the components\\\
private JRadioButton oneWay;
private JRadioButton roundTrip;
private ButtonGroup buttonGroup;
private JLabel fromDestdLabel;
private JComboBox fromDestCb;
private JLabel toDestLbl;
private JComboBox toDestCb;
private JLabel departLbl;
private JComboBox departMonth;
private JComboBox departDay;
private JTextField departYear;
private JLabel arriveLbl;
private JComboBox arriveMonth;
private JComboBox arriveDay;
private JTextField arriveYear;
private JLabel adultLbl;
private JComboBox adultCb;
private JLabel childLbl;
private JComboBox childCb;
private JLabel infantLbl;
private JComboBox infantCb;
private JButton searchBtn;
private JButton canxBtn;
private JPanel buttonPane;
private JPanel dataPane;
public SearchFlight(){
initcomp();
}
public void initcomp(){
//initilizing all the componets\\
oneWay = new JRadioButton("One Way");
roundTrip = new JRadioButton("Round Trip");
buttonGroup = new ButtonGroup();
fromDestdLabel = new JLabel("From");
fromDestCb = new JComboBox();
toDestLbl = new JLabel("To");
toDestCb = new JComboBox();
departLbl = new JLabel("Depart");
departMonth = new JComboBox();
departDay = new JComboBox();
departYear = new JTextField();
arriveLbl = new JLabel("Arrive");
arriveMonth = new JComboBox();
arriveDay = new JComboBox();
arriveYear = new JTextField();
adultLbl = new JLabel("Adult");
adultCb = new JComboBox();
childLbl = new JLabel("Child");
childCb = new JComboBox();
infantLbl = new JLabel("infant");
infantCb = new JComboBox();
searchBtn = new JButton("Search");
canxBtn = new JButton("Cancel");
buttonPane = new JPanel();
dataPane = new JPanel(new GridBagLayout());
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
BorderLayout borderLayout = new BorderLayout();
c.fill = GridBagConstraints.HORIZONTAL;
dataPane.setLayout(borderLayout);
c.gridx = 1;
c.gridy = 0;
dataPane.add(oneWay, c);
c.gridx = 2;
c.gridy = 0;
dataPane.add(roundTrip, c);
c.gridx = 0;
c.gridy = 1;
dataPane.add(fromDestdLabel ,c);
c.gridx = 1;
c.gridy = 1;
c.gridwidth = 2;
dataPane.add(fromDestCb, c);
c.gridx = 0;
c.gridy = 2;
dataPane.add(toDestLbl,c);
c.gridx = 1;
c.gridy = 2;
dataPane.add(toDestCb, c);
c.gridwidth = 1;
c.gridx = 0;
c.gridy = 3;
dataPane.add(departLbl ,c);
c.gridx = 1;
c.gridy = 3;
dataPane.add(departMonth,c);
c.gridx = 2;
c.gridy = 3;
dataPane.add(departDay, c);
c.gridx = 3;
c.gridy = 3;
dataPane.add(departYear, c);
c.gridx = 0;
c.gridy = 4;
dataPane.add(arriveLbl, c);
c.gridx = 1;
c.gridy = 4;
dataPane.add(arriveMonth, c);
c.gridx = 2;
c.gridy = 4;
dataPane.add(arriveDay,c);
c.gridx = 3;
c.gridy = 4;
dataPane.add(arriveYear,c);
c.gridx = 0;
c.gridy = 5;
dataPane.add(adultLbl,c);
c.gridx = 1;
c.gridy = 5;
dataPane.add(adultCb,c);
c.gridx = 0;
c.gridy = 6;
dataPane.add(childLbl,c);
c.gridx = 1;
c.gridy = 6;
dataPane.add(childCb,c);
c.gridx = 0;
c.gridy = 7;
dataPane.add(infantLbl,c);
c.gridx = 1;
c.gridy = 7;
dataPane.add(infantCb,c);
buttonPane.add(searchBtn);
buttonPane.add(canxBtn);
add(buttonPane, BorderLayout.SOUTH);
add(dataPane);
}
}