GuptillGunther
GuptillGunther

Reputation: 21

Initializing a JComboBox object using a String array

I did it as follows, but it wouldn't work:

JComboBox brand = new JComboBox({"Pizza Hut", "Papa John's", "Dominos" });

The error is: Syntax error on token "new", @ expected after this token

Kindly help me understand what the problem is.

Upvotes: 0

Views: 1358

Answers (1)

MadProgrammer
MadProgrammer

Reputation: 347184

You can't short cut the creation of the array, you need to provide more information so the compiler can resolve the types, for example

JComboBox brand = new JComboBox(new Object[]{"Pizza Hut", "Papa John's", "Dominos" });

Upvotes: 4

Related Questions