Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

JCombobox question

Posted on 2003-02-25
4
Medium Priority
?
191 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:rimmer0007
  • 2
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 300 total points
ID: 8020222
String index = new Integer(def.getSelectedIndex()).toString();
0
 

Author Comment

by:rimmer0007
ID: 8020370
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"
0
 

Author Comment

by:rimmer0007
ID: 8020423
ahh because getSelectedIndex returns an INT
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 8020738
yes, and if you want the text,
def.getSelectedItem();

;)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Don’ts and Dos are two important end products of software testing basics that a tester needs to regard. This article attempts to explain the principles of both.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question