Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-02-2007, 12:01 AM
Member
 
Join Date: Jun 2007
Posts: 92
Marcus is on a distinguished road
Help with jComboBox
Hello, I have a combo box, which a user selects a type of database(access, oracle or mysql). I need to determine which database the user is choosing, and am not quite sure how to get the value out of the combo box.

Have tried to use jComboBox.getSelectedItem(), but this returns an object, not a String.

Thanks.

Marcus
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-02-2007, 12:03 AM
Senior Member
 
Join Date: Jun 2007
Posts: 114
Albert is on a distinguished road
A String Is a Object

What happens when you cast the result to a String?
Code:
... String selection = (String)jComboBox.getSelectedItem(); ...
Greetings.

Albert
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-02-2007, 12:08 AM
Senior Member
 
Join Date: Jun 2007
Posts: 111
Eric is on a distinguished road
Just so you know, Swing widgets return Objects as opposed to Strings so that you can use Objects other than Strings as your selection choices. It's relatively simple to do this: Just correctly override toString() in the Object type you are adding to the widget, and it'll display the text from toString(), but will return the actual object.

So as a design consideration, you might consider creating a database connection info object. One that encapsulates ALL the information required to connect. If this object overrides toString() with something meaningful - example "Accounting database" - then you will receive back a meaningful object that you can use, but you'll see the contents of the "toString()" method on the screen. As opposed to having to construct it after the selection is made.

Greetings.

Eric
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change font/ font color etc in a graphic object using JCombobox? JavaInLove AWT / Swing 0 02-07-2008 12:28 PM
Canvas rendered over JCombobox menu JSK AWT / Swing 2 11-19-2007 09:00 PM
Adding items to a jComboBox tronovan New To Java 0 08-08-2007 09:48 AM
JComboBox setDisabledTextColor Jack AWT / Swing 2 07-02-2007 06:32 AM
jcombobox Freddie AWT / Swing 4 05-11-2007 01:48 AM


All times are GMT +3. The time now is 06:19 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org