[英]Saving a JComboBox Selection to an ArrayList
I cannot retrieve the selection in the JComboBox that was selected by the user. 我无法在用户选择的JComboBox中检索选择。 the J ComboBox inclued a list of car registration numbers, which then the user has to select one and it will be added to the booking ArrayList.
J ComboBox包含一个汽车登记号码列表,然后用户必须选择一个,然后它将被添加到预订ArrayList中。 Unfortunately it is not working properly.
不幸的是,它不能正常工作。 and the booking is not being saved because of this.
并且因此无法保存预订。 Please Help Me!
请帮我! Maybe I need to change the get Method for the combo box.
也许我需要更改组合框的get方法。
ArrayList BookingList = CarRentalSystem.BookingList;
ArrayList CarList = CarRentalSystem.CarList;
UsingFiles BookingFile = CarRentalSystem.BookingFile;
String [] regNums;
public NewBooking() {
regNums = new String[CarList.size()+1];
for (int i = 0; i< CarList.size();i++){
regNums[i] = ""+((Car)CarList.get(i)).getCarNum();
}
initComponents();
....
Booking book = new Booking();
String regNum = cmbCar.getActionCommand();
book.getRegNum();
Not easy to understand what u want can you add more code? 不容易理解您想要什么,您可以添加更多代码吗?
try this to convert your list into a String Array that u pass in as a argument to your combobox. 尝试将此操作将您的列表转换为字符串数组,然后将其作为参数传递给组合框。
public String[] regNums() {
String tArray[] = null;
for (int i=0; i<carList.size(); i++){
//Convert into a String[] and put the arrayList values in it.
tArray = carList.toArray(new String[i]);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.