JCombobox question

Posted on 2003-02-25
Medium Priority
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();

Question by:rimmer0007
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 18

Accepted Solution

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

Author Comment

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"

Author Comment

ID: 8020423
ahh because getSelectedIndex returns an INT
LVL 18

Expert Comment

ID: 8020738
yes, and if you want the text,


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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month8 days, 14 hours left to enroll

764 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