Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将JComboBox选择保存到ArrayList_Java_Swing_Netbeans_Selection_Jcombobox - Fatal编程技术网

Java 将JComboBox选择保存到ArrayList

Java 将JComboBox选择保存到ArrayList,java,swing,netbeans,selection,jcombobox,Java,Swing,Netbeans,Selection,Jcombobox,我无法检索用户在JComboBox中选择的内容。J组合框包括一个汽车登记号码列表,用户必须选择一个,然后将其添加到预订列表中。不幸的是,它不能正常工作。因此,预订没有被保存。请帮帮我!也许我需要更改组合框的get方法 ArrayList BookingList = CarRentalSystem.BookingList; ArrayList CarList = CarRentalSystem.CarList; UsingFiles BookingFile = CarRentalSystem.Bo

我无法检索用户在JComboBox中选择的内容。J组合框包括一个汽车登记号码列表,用户必须选择一个,然后将其添加到预订列表中。不幸的是,它不能正常工作。因此,预订没有被保存。请帮帮我!也许我需要更改组合框的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();
ArrayList BookingList=CarRentalSystem.BookingList;
ArrayList CarList=CarRentalSystem.CarList;
UsingFiles BookingFile=CarRentalSystem.BookingFile;
字符串[]regNums;
公共新图书{
regNums=新字符串[CarList.size()+1];
对于(int i=0;i
不容易理解您想要什么您可以添加更多的代码吗

尝试将列表转换为字符串数组,并将其作为参数传递给组合框

    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]);                
        }
    }
公共字符串[]regNums(){
字符串tArray[]=null;

对于(int i=0;i)代码与什么相关?学习如何创建一个“你不能”的词是什么意思?这段代码是做什么的?它编译了吗?它运行了吗?它是否表现出一些奇怪的行为?还有什么?你的呢?是的,它运行了。这是一个租车系统。用户将新车保存在arrayList CarList中。这包括我随后在组合框中显示的注册号。但是当用户从组合框中选择字段时x、 它未存储在booking arraylist中。组合框的侦听器在哪里?如果选择有问题,则必须显示侦听器代码,因为这是选择的来源。如果您不知道侦听器是什么,请参阅@onoitsjon-“JComboBox或按钮上是否有侦听器?”(附加了一个操作)调用JComboBox.getSelectedItem()或JComboBox.getSelectedIndex()?“我已经将其转换为字符串。我只需要获得正确的方法而不是getActionCommand()来检索信息