Results 1 to 5 of 5
- 05-10-2009, 09:42 PM #1
Member
- Join Date
- Jan 2009
- Posts
- 18
- Rep Power
- 0
Jcombobox not liking String input for options :|
Hey there,
Slight issue here where i have a loop pulling usernames out of a mysql database and creating a string which outputs all the usernames and connects them to form a string such as "name1" , " name2" , "name3" , "name4" , etc.
This String is then put in a JCombobox ("concatonated" ?!) for example.
in the GUI class,
instead of:
I have, in the first class:Java Code:String[] cmbouser = {" Select username " , " Joe " , " Mike " , " Valsilis " ,};
Custusers is technically equal to {" Joe " , " Mike " , " Vasilis " ,} so does anyone know why the combobox ends up just displaying first { Select username } and then second on the list there is {" Joe " , " Mike " , " Vasilis " ,} as the only second option :|Java Code:custusers = Data.getcustusers(); String[] cmbouser = {" Select username " , custusers};
I'm aiming to have all the users pulled out of the sql database on the combobox list.
Am i going about this in the wrong way?
Is there any way around this combobox issue?
Oh and lastly, i dont suppose anyone has any pointers to any material on Jcombobox action listeners and such?
Am looking forward to any replies and am starting to read posts hoping i can start giving back someday soon if i ever *get there* heh.
Best regards
-Jvr
-
What is the customers object exactly?
You say,but it's likely a single String, and this isn't an array. Even if it were, you're code wouldn't work.Custusers is technically equal to {" Joe " , " Mike " , " Vasilis " ,}
Remember programming is unforgiving. When the API tells you that if you pass an Array of objects into a combo box constructor, you will see the toString representation of those objects, you have to do exactly that. It appears that you are passing an array of two Strings into this combo box, the first being " Select username ", and the second being a String containing concatenated other Strings. The combo box will then do exactly as you told it to: it will display the two Strings.
What you want to do instead is create a single array with all the strings, probably starting with " Select username " and then containing all the other Strings each as a separate item in the array. This may require a for loop to create. Then use this array to initialize your combo box.Last edited by Fubarable; 05-10-2009 at 10:13 PM.
- 05-10-2009, 11:16 PM #3
Member
- Join Date
- Jan 2009
- Posts
- 18
- Rep Power
- 0
Hey there,
As usual, your blinding with your logic heh.
As you say, i'm using a while loop which pulls out each user in turn and encloses them in the required character dressing:
Mmm,Java Code:while (rs.next()) { String b = rs.getString("fname"); String c = rs.getString("lname"); .... etc etc.... users = users + " \" "+ b +" \","; }
Back to arrays i guess.
I shall look into storing and initialising from an array :)
Muchos gracious :)
-Jvr
-
Or another option is to use a Vector<String> as a combo box can use this in its constructor. You could add your Strings from the dataset and then later append your " select..." String to index position one.
Another option is to use a DefaultComboBoxModel
- 05-11-2009, 12:34 PM #5
Member
- Join Date
- Jan 2009
- Posts
- 18
- Rep Power
- 0
Similar Threads
-
[SOLVED] Reading an input string?!
By sfe23 in forum New To JavaReplies: 6Last Post: 02-23-2009, 04:38 AM -
How to Mask input string
By nmc.091 in forum New To JavaReplies: 1Last Post: 02-23-2009, 03:49 AM -
Prompting user input of a string.
By apfroggy0408 in forum New To JavaReplies: 3Last Post: 03-09-2008, 06:23 PM -
ComboBox with database options
By Goldy in forum Advanced JavaReplies: 0Last Post: 12-01-2007, 09:43 PM -
problem with Java Vm options
By DonnieDarko in forum Advanced JavaReplies: 1Last Post: 11-21-2007, 03:22 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks