Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 02-21-2009, 03:01 AM   #1
Registered: Dec 2008
Location: Kerala, India
Distribution: Ubuntu 11.10
Posts: 334

Rep: Reputation: 33
Cool How to add numbers in JComboBox

I will show a small snippet what i did :

1. JComboBox petList = new JComboBox();
2. petList.addItem(1);// also tried petList.addItem(new Integer(1));

When i tried to enter string in combo box its ok , working fine , but when tried to enter numbers its bit problem ..

Error shown ...

java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

Last edited by vibinlakshman; 02-21-2009 at 03:02 AM.
Old 02-21-2009, 02:10 PM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

You can always use "String.valueOf()":
String s = String.valueOf(i);
Even easier, you can probably just concatenate an empty string:
petList.addItem("" + i);
'Hope that helps .. PSM


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
using bc to add numbers and put into variable disruptive Programming 3 05-26-2008 09:05 PM
Bash + How to add Hexadecimal numbers trscookie Programming 7 09-03-2007 04:22 PM
Perl add numbers in 2nd field twantrd Programming 6 10-19-2006 08:26 PM
Add consecutive numbers to a Chinese file tcma Linux - General 0 10-19-2004 03:25 PM
Help.. how do I add two numbers? Tengil Linux - Newbie 3 03-04-2004 12:58 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:59 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration