?
Solved

JCombobox question

Posted on 2003-02-25
4
Medium Priority
?
190 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
[X]
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
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

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