Click here to Skip to main content
14,935,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have been creating a gui which has a comboBox.I am not able to initialise the combo box items and I get syntax error on below pasted code.

What I have tried:

ScrollPane scrollPane = new JScrollPane();
comboBoxSelection = new JComboBox<>();
//Below line has the error
comboBoxSelection.setModel(new DefaultComboBoxModel(new <string>("HOUSEBOAT_ID","HOUSEBOAT_NAME","HOUSEBOAT_CAPACITY","BOOKING_DATE","CUSTOMER_NAME","CUSTOMER_ID")));
Updated 26-Apr-21 5:25am

1 solution

Your definitions are not valid. Try the following:
JComboBox comboBoxSelection = new JComboBox<>();
comboBoxSelection.setModel(new DefaultComboBoxModel(new String[]{"HOUSEBOAT_ID","HOUSEBOAT_NAME","HOUSEBOAT_CAPACITY","BOOKING_DATE","CUSTOMER_NAME","CUSTOMER_ID"}));
CPallini 26-Apr-21 12:04pm
Richard MacCutchan 26-Apr-21 12:18pm
Nandini Sathyan S 26-Apr-21 23:16pm
Thank You!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900