• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why? this piece of code is not working

 
joseph okon
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String sexbox[] = {"Male","Female"};
String marbox[] = {"Married","Single","Deviorced"};
JComboBox sexcb = new JComboBox();
sexcb.addItem(sexbox);

JComboBox mar_statuscb = new JComboBox();
mar_statuscb.addItem(marbox);

the error i get is:<identifier> expected
what can i do ?

[ January 16, 2008: Message edited by: joseph okon ]
[ January 16, 2008: Message edited by: joseph okon ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 49472
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is because you called it "sexcd" in one place and "sexcb" in another.
 
Mark Newton
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did Campbell's solution solve your problem? You seem to have edited your code to fix the mistake that Campbell pointed out. Does that mean the problem's fixed?
 
Brian Cole
Author
Ranch Hand
Posts: 907
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by joseph okon:
String sexbox[] = {"Male","Female"};
JComboBox sexcb = new JComboBox();
sexcb.addItem(sexbox);


You are adding the array itself as an item to the combo box.
This will result in only a single item in the box, which the
renderer will show as something ugly like [Ljava.lang.String;@123456

You probably want to add each item of the array to the combo box.
The easy way is do just do JComboBox sexcb = new JComboBox(sexbox).
You could also do
sexcb.addItem(sexbox[0]);
sexcb.addItem(sexbox[1]);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic