Link to home
Start Free TrialLog in
Avatar of rimmer0007
rimmer0007

asked on

JCombobox question

i m trying to convert def.getSelectedIndex() to a String is it possible to do that? i m trying it below but get a cast error can anyone help


private String string[] = {"Default", "Swing"} ;
 def = new JComboBox(string);
String index = (String)def.getSelectedIndex();

thxs
ASKER CERTIFIED SOLUTION
Avatar of bobbit31
bobbit31
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rimmer0007
rimmer0007

ASKER

thxs do you mind answering my below question saves opening a new thread

i m doing a  System.out.println(index);
why is it printing out the number and not the string "Default" "Swing"
ahh because getSelectedIndex returns an INT
yes, and if you want the text,
def.getSelectedItem();

;)